ccma14 commented on a change in pull request #831: ZOOKEEPER-3286: xid 
wrap-around causes connection loss/segfault when hitting predefined XIDs
URL: https://github.com/apache/zookeeper/pull/831#discussion_r264013463
 
 

 ##########
 File path: zookeeper-client/zookeeper-client-c/src/mt_adaptor.c
 ##########
 @@ -502,13 +502,13 @@ int32_t fetch_and_add(volatile int32_t* operand, int 
incr)
 }
 
 // make sure the static xid is initialized before any threads started
-__attribute__((constructor)) int32_t get_xid()
 
 Review comment:
   __attribute__((constructor)) is no longer needed since the following 
statement was removed:
   
   if (xid == -1) {
       xid = time(0);
   }
   
   Having this statement is what made the function not MT safe (that's the racy 
initialization that the comment talks about).  -- The only way that the MT 
version of get_xid now manipulates the xid static variable is via an atomic 
increment.
   
   For the single threaded version of get_xid i stuck with
   
   return xid++ & ~(1<<31);
   
   to keep the behavior of the ST and MT version of get_xid identical, but if 
you want me to i can change that...

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to