Re: Simple Flag on SMP

From: Thomas Richter (thor_at_cleopatra.math.tu-berlin.de)
Date: 11/04/03


Date: 4 Nov 2003 12:42:33 GMT

Hi,

> 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?

Yes.

> 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.

So long,
        Thomas



Relevant Pages

  • Re: Simple Flag on SMP
    ... > suppose I have a simple flag that is being operated on by ... > multiple CPUs (SMP system) concurrently. ... > volatile is to weak for SMP, ...
    (comp.os.linux.development.system)
  • Simple Flag on SMP
    ... suppose I have a simple flag that is being operated on by ... multiple CPUs (SMP system) concurrently. ... The flag is of type int and ...
    (comp.os.linux.development.system)
  • Re: [patch] burncd: honour for envar SPEED
    ... Gabor Kovesdan schrieb am 2009-11-09: ... The speed variable is of type int, while getenv ... +flag. ...
    (freebsd-hackers)