From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu From: "Thomas Bushnell, BSG" Message-ID: <87g03lh7qc.fsf@becket.becket.net> Content-Type: text/plain; charset=us-ascii References: <3C7CFAFE.4996DA2A@research.bell-labs.com>, <87u1s2y1uu.fsf@becket.becket.net>, Subject: Re: [9fans] plan or side effect Date: Thu, 28 Feb 2002 16:52:54 +0000 Topicbox-Message-UUID: 5c13f43c-eaca-11e9-9e20-41e7f4b1d025 "AMSRL-CI-CN" writes: > "Thomas Bushnell, BSG" wrote in message > news:87u1s2y1uu.fsf@becket.becket.net... > > In the presence of concurrence, even this is not sufficient, because a > > different thread could clobber the value. However, C does not > > guarantee synchronization in this case unless the variable is marked > > "volatile". > > Actually the C standard does not address threads at all. > It is nice that "volatile" helps, but I'm sure it doesn't totally > solve the concurrent data access problem for threads. No, certainly not! I misspoke. I shouldn't have said "synchronization", which does imply more, and certainly you still need mutexes or semaphores or something. "volatile" is a declaration to the compiler that the value could be changing at any time, unbeknownst to the compiler, and so values can't be cached in registers. If "acquire mutex" is a function call, then you don't even need to declare the variable volatile, since the compiler knows that the function call could clobber all of memory. So it isn't even necessary for threads, if you *are* using mutexes, and for other reasons you certainly do need to. So the reference to threads was a needless confusion; sorry. Thomas