9aaeb47e   
   From: ulrich.eckhardt@dominolaser.com   
      
   Am 14.02.2012 11:38, schrieb Hei:   
   > class A {   
   > public:   
   > std::map m_myMap;   
   > A::A() {   
   > m_myMap[0] = new B();   
   > pthread_t threadID;   
   > pthread_create(&threadID, NULL, start, NULL);   
   > }   
   > static void* start(void*) {   
   > // use m_myMap[0] here   
   > }   
   > }   
   >   
   > I wonder whether m_myMap[0] may contain some invalid value since the   
   > new thread might be in another CPU that might not see the change to   
   > m_myMap[0] in the constructor yet (i.e. the change only 'exists' in   
   > one of the CPU's caches).   
      
   The C++ language doesn't define this, making this rather off-topic and better   
   asked in comp.programming.threads (IIRC). That said, thread creation is   
   generally a barrier, so anything done before creating the thread will be   
   visible inside the thread.   
      
   There is a C++ issue though: The thread entry must be declared extern "C". A   
   class-static works in many cases though, but formally it is undefined. I'd   
   suggest using the new C++ threading facitilies btw, or Boost.Thread, both of   
   which present a    
   friendlier interface to multithreading in C++.   
      
   Good luck!   
      
   Uli   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|