Subj : Re: 'volatile' Rules To : comp.programming.threads From : Joe Seigh Date : Tue Jun 07 2005 03:01 pm Marcin 'Qrczak' Kowalczyk wrote: > "Uenal Mutlu" <520001085531-0001@t-online.de> writes: > > >>There seems indeed be no good reason to use volatile: >>it's unsafe/unreliable/unpredictable and a performance killer, >>in short: totally useless. >>Maybe someone can list when it is ever useful, if any. > > > It is useful for communication between a Unix signal handler and the > main program (they should run in the same thread). > > setjmp requires volatile on local variables of the function performing > setjmp if their values should be correctly preserved across longjmp. > > volatile might be useful for memory mapped files, to ensure that > intermediate states in the middle of operations look predictably. > This is not true. It's nonsense even. If someone wrote it into the documentation, they didn't know what they're talking about. Signal handling has visibility rules analogous to the way pthreads has visibility rules. They are also not documented which is also analogous to pthread's rules not being documented. Volatile buys you nothing in this case just like it buys you nothing for pthreads. Signal handling uses the same undocumented mechanisms for visibility that pthreads uses, except obviously they don't need memory barriers since it's all on the same thread. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .