Subj : Re: Lock-free buffer To : comp.programming.threads From : Joe Seigh Date : Fri Mar 04 2005 03:39 pm On 4 Mar 2005 12:05:50 -0800, allan wrote: > I am really curious if there exists the lock-free buffer algorithm. > Lock-free queue, lock-free list, etc. are there, but is there the > algorithm for the lock-free buffer? > > Lock-free queue is not sufficient for my case, because in the case > where three readers try to read a data and the lock-free queue has > only one data, only one of readers would get data with dequeue() > operation and the other two should wait until writers fill data into > the queue with enqueue() operation. In short, all readers should be > guaranteed to get the latest updated data all the time. > > If anybody advices me, it would be deeply appreciated. > It sounds like you want a shared buffer. A queue is a totally different thing. Yes, you can do it with COW (copy on write) which will allow lock-free reads of the buffer. atomic_ptr, RCU (Read, Copy, Update), SMR hazard pointers, Boehm style GC, etc... will let you do that. Updating the buffer lock-free will require compare and swap or some other interlocked primative. -- Joe Seigh .