Subj : Avoiding synchronization (pthreads) To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Wed Mar 02 2005 03:39 pm 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? 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). -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .