Re: Simple Flag on SMP
From: Thomas Richter (thor_at_cleopatra.math.tu-berlin.de)
Date: 4 Nov 2003 12:42:33 GMT
> suppose I have a simple flag (a boolean) that is being operated on by
> multiple CPUs (SMP system) concurrently. The flag is of type int and
> accessing a int is guaranteed to be atomic on Linux (isn't it?).
I don't see why it should in general.
Even here you should make this "volatile" if you access it from different
threads since the compiler might change the order of accesses.
> I am concerned about, that the flag's status, when changed, becomes not
> immediately visible to other CPUs (because of caching or whatever).
> Maybe qualifying the flag as volatile would do, but I have read that
> volatile is to weak for SMP, is that true?
> What are other alternatives to volatile?
Using a construction like semaphores or mutex's to represent your
data, for example. It is then the matter of the stdlib to implement
the gory details.