Hi Tim, On Sat, May 11, 2002 at 03:51:09PM +0200, Tim Goetze wrote: > i'm evaluating the following construct to implement a lock-free fifo > that allows more than one thread on the writer side: > > here, the i386 'xadd' instruction atomically adds 'i' to the counter > variable and returns the counter value before the add (obviously this > restricts the fifo size to powers of two so counter overflow can > safely be ignored). > > do you happen to know about the availability of an analogon to this > code on other processors than i386?
Look into the implementation of atomic_add() of your favorite arch, because you just re-invented it badly ;-) The problem is, that on some archs atomic operations are implemented using privileged instructions, so they cannot be used in user space. But Linux 2.5 will have fast user space mutexes (the implementor calls these "futexes"), so you are basically wasting your time here ;-) Regards Ingo Oeser -- Science is what we can tell a computer. Art is everything else. --- D.E.Knuth
