Subj : Re: Did pthread_once init_routine succeed? To : comp.programming.threads From : David Schwartz Date : Wed Feb 23 2005 07:53 pm wrote in message news:1109216013.290684.281110@f14g2000cwb.googlegroups.com... > I agree completely, but one question: > Should we be concerned about the memory-visibility of the global > variable - ie maybe the second thread, on a second processor, will > still be seeing the old value of the global variable, because the CPU's > cache is not in sync with the other thread's CPU's cache. If you had to worry about that, pthread_once would be useless. It would be unsuitable for its intended purpose, namely preventing a thread from proceeding before some kind initialization is complete. > ie do we need a memory barrier on the read of the global variable? No. If you follow the POSIX standard, you never need memory barriers. In fact, POSIX doesn't even mention them. Specifically, pthread_once guarantees visibility of all changes made in the initialization routine once a thread returns from the call to pthread_once. DS .