Subj : double-checked locking in C To : comp.programming.threads From : amorox Date : Tue Jul 05 2005 03:54 pm Hi, I would like to use the DCL idiom (double-checked locking) to guarantee the once and only once execution of an initialization code: bool initialized = false; pthread_mutex_t mutex; void function(void) { if (!initialized) { pthread_mutex_lock(&mutex); if (!initialized) { initialized = true; init_code(); } pthread_mutex_unlock(&mutex); } } I know that in Java there were problems with this idiom due to the memory operation reorderings and these have been apparently solved in Java 1.4. Is there any problem using this idiom in a multithread C program? If affirmative would you explained why? Thanks, Ovi P.S.: I know the problem may be solved by using 'pthread_once' protection. .