Re: cross platform 64bit lock free FIFO?
George Warner <[email protected]> Mon, 21 Aug 2006 09:36:07 -0700
| Newsgroups | gmane.games.devel.general |
|---|---|
| Message-ID | <C10F2F07.2E4BD%[email protected]> |
On Wed, 09 Aug 2006 09:26:20 -0700, Jon Watte <[email protected]> wrote: > Here is the implementation, an all its simplicity: > > // Lock-free FIFO by Jon Watte. > // Size must be power of 2. This restriction could be removed by using a modulus operation instead of the AND. (Probably a safe assumption that this restriction was done as a compromise to speed (Not necessary on PPC)). At the least I'd add an assert to verify that Size is a power of 2. assert( !(Size & ( Size - 1 ) ); // only zero for exact powers of 2 Other than that this code is really only useful for a single provider & consumer. There's a race condition between the full/empty tests and the tail/head increments that wouldn't work with multiple writers/readers. (Yes, validating race conditions acerbates my schizophrenia. ;-) I'd also add code to optionally block on the failure cases (read-empty & write-full) and when a thread is blocked signal a wakeup when the failure case is invalidated (queue goes non-empty when a reader is blocked or queue goes non-full when a writer is blocked). For the single provider/consumer case you still wouldn't need the lock; Just a condition variable for signaling. -- Enjoy, George Warner, Schizophrenic Optimization Scientist Apple Developer Technical Support (DTS) ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Gamedevlists-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=557