Messages in this thread | | | Subject | Re: ordered memory access | From | Jes Sorensen <> | Date | 30 Sep 1999 13:39:42 +0200 |
| |
>>>>> "Manfred" == Manfred Spraul <manfreds@colorfullife.com> writes:
Manfred> I try to thread ipc/msg.c. My new design is nearly finished, Manfred> but I have one problem: In a certain case, I want to rely on Manfred> memory ordering instead of a spinlock:
Manfred> struct test { atomic_t a; atomic_t b; } CPU1: Manfred> atomic_set(a,return_value); atomic_set(b,1234);
Manfred> CPU2: if(atomic_read(b) == 1234) return atomic_read(a);
Manfred> IIRC, the x86 CPU can reorder read ahead of write, and Manfred> atomic_read(), atomic_set() are normal read/write operations, Manfred> so is this code SMP safe? Which memory barrier calls are Manfred> required for portability?
atomic_foo() should be ordered, at least that the idea behind it as far as I understand.
Otherwise you want to look at mb(), rmb() and wmb(). mb() is a generic memory barrier, wmb() makes sure a write is issues before another write() and rmb() ... you get the idea ;-)
Jes
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |