volatile and barriers (especially on PPC)

Doug Lea dl at cs.oswego.edu
Sat Mar 12 00:45:44 GMT 2005


Peter wrote:


> (Personal comment) I've never liked "volatile" because it borders on 
> witch-craft.

We all agree! We are taking the witchcraft out of it! It will
now means something very specific and useful, that just by chance
happens to also cover all the cases it was previously allegedly
necessary too. What could be nicer?

> Try explaining to a class of 2nd or 3rd year students the reasons for
> when it is necessary to qualify a variable with "volatile". You
> are not going to be very successful.


I bet you can get them to understand that you use volatile for
any (scalar or pointer) variable that is accessed across multiple
threads without a lock. And further that you only do such things
when implementing lock-free constructions, only a small handful
of which are useful enough to learn and master. At least my Java
concurrency course students seem to understand that :-)


-Doug






More information about the cpp-threads mailing list