lkml.org 
[lkml]   [1999]   [Sep]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: ordered memory access
From
Date
>>>>> "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/

\
 
 \ /
  Last update: 2005-03-22 13:54    [W:0.073 / U:0.344 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site