Subj : Re: 'volatile' Rules To : comp.programming.threads From : Marcin 'Qrczak' Kowalczyk Date : Tue Jun 07 2005 03:24 pm "Uenal Mutlu" <520001085531-0001@t-online.de> writes: > Rule: volatile is not necessary if (a OR (b AND c AND d) holds: > a) variable is used in a locked state (ie. protected via mutex etc.). > b) size of variable <= machine word. > c) variable is aligned on machine word boundary > (ie. its start adress is an integral multiple of machine word size). > d) within the same func there is at least 1 "funccall" before > subsequent queries to, or modifications of, the variable. Since without memory synchronization (which is done e.g. by locking and unlocking mutexes) you can't reliably access data from multiple threads, volatile is not necessary for multithreading at all. Except various lock-free algorithms, but there volatile is not enough - they typically need atomic operations which also synchronize memory between threads, not available in ISO/ANSI C nor even in POSIX. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/ .