question on semantics
Chris Friesen
cfriesen@nortel.com
Wed May 4 21:15:00 GMT 2005
Diego Novillo wrote:
> On Wed, May 04, 2005 at 01:47:20PM -0600, Chris Friesen wrote:
>
>
>>Also, what about threads and pthread locking? Do I need to use volatile
>>there? If not, then what about using pthread locking between processes?
> Things will only break for you when GCC pulls in function bodies
> at link time. At that point, yes, you will need to declare your
> pointed-to area as volatile.
Dave Butenhof (author of "Programming with POSIX Threads") seems to
disagree with that position:
"In general, use of "volatile" for variables that are simply shared
between threads is unnecessary and wasteful. Proper synchronization is
necessary and sufficient; there is no substitute short of coding
carefully with specific knowledge of the memory architecture of a
specific platform."
In multiple messages to comp.programming.threads he has stated that
volatile is not necessary between threads if you use the posix locking
functions, and in fact that one of the main purposes of the posix locks
is to ensure correct memory visibility between threads.
Chris
More information about the Gcc
mailing list