C++ objects in multithreading -


i ask thread safety in c++ (using posix threads c++ wrapper ex.) when single instance/object of class shared between different threads. example member methods of single object of class called within different threads. should/can thread safety?

class {     private:      int n;      public:      void increment()     {         ++n;     }      void decrement()     {         --n;     } }; 
  • should protect class member n within increment/decrement methods lock or else? static (class variables) members have such need lock?
  • if member immutable, not have worry it, right?
  • anything cannot foreseen now?

in addition scenario single object within multithreads, multiple object multiple threads? each thread owns instance of class. special other static (class variables) members?

these things in mind, believe large topic , glad if have resources , refer previous discussions that.

regards

suggestion: don't try hand. use multithread library 1 boost: http://www.boost.org/doc/libs/1_47_0/doc/html/thread.html

this article intel give overview: http://software.intel.com/en-us/articles/multiple-approaches-to-multithreaded-applications/


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -