9aaeb47e   
   From: hfollmann@itcfollmann.com   
      
   On 2012-02-14, Hei wrote:   
   > Hi,   
   >   
   > Here is my pesudocode:   
   >   
   > class B {};   
   >   
   > 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).   
   >   
   > Thanks in advance.   
   >   
   >   
      
   Well, yes you do.   
   And more. Usually I wouldn't create threads in a constructor. Also your   
   threadID is not accessible after you finished A::A().   
      
   -H   
      
   --   
   Henning Follmann | hfollmann@itcfollmann.com   
      
      
    [ 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)   
|