Subj : Re: Avoiding synchronization (pthreads) To : comp.programming.threads From : David Hopwood Date : Sun Mar 06 2005 01:52 am Marcin 'Qrczak' Kowalczyk wrote: > If a global variable of type int is read without holding a mutex, at > the same time as other threads may write into it (holding the mutex), > can anything worse than getting an out-of-date value happen in practice? No, not on any platform I'm aware of. > The variable in question counts the number of threads. It is used > to avoid locking in case there is only one thread. There may be > background threads terminating asynchronously which decrement the > variable. If the first paragraph is true, I should be safe, because > an out-of-date value can only be larger than the true value, and > in this case I will execute an equivalent but slower code (which > takes the mutex, so the next time the variable will be up to date). I'm confused as to why you're attempting this optimization; it can probably be made to work, but I can't see how avoiding locking here could result in any *signficant* performance benefit. -- David Hopwood .