Re: Simple Flag on SMP
From: Neil Horman (nhorman_at_rNeOdShPaMt.com)
Date: 11/04/03
- Next message: Tuukka Toivonen: "Re: Simple Flag on SMP"
- Previous message: Thomas Richter: "Re: Simple Flag on SMP"
- In reply to: Frank A. Uepping: "Simple Flag on SMP"
- Next in thread: Tuukka Toivonen: "Re: Simple Flag on SMP"
- Reply: Tuukka Toivonen: "Re: Simple Flag on SMP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 04 Nov 2003 09:47:17 -0500
Frank A. Uepping wrote:
> 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 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?
>
> /FAU
>
No guarantees regarding the atomicity of an access in linux. What if
you have a multithreaded app running on an smp system with load-store
style processors (powerpc, alpha, mips, etc). They take at least three
instructions to update an integer value (load-modify-store). It may
work to assume that integer accesses are atomic on some systems, but its
not at all portable. If you want to guarantee it, you need to use
mutexes or semaphores to protect your data.
Neil
-- /*************************************************** *Neil Horman *Software Engineer *Red Hat, Inc., www.redhat.com *gpg keyid: 1024D / 0x92A74FA1 *http://www.keyserver.net ***************************************************/
- Next message: Tuukka Toivonen: "Re: Simple Flag on SMP"
- Previous message: Thomas Richter: "Re: Simple Flag on SMP"
- In reply to: Frank A. Uepping: "Simple Flag on SMP"
- Next in thread: Tuukka Toivonen: "Re: Simple Flag on SMP"
- Reply: Tuukka Toivonen: "Re: Simple Flag on SMP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|