Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch > #31415

Re: Efficient lock free FIFO

Newsgroups comp.arch
Date 2015-12-04 01:59 -0800
References <ec9545f0-93a8-4672-8f59-695eee864d30@googlegroups.com>
Message-ID <e7740fc3-617b-418f-bd8d-be7d1f474ac8@googlegroups.com> (permalink)
Subject Re: Efficient lock free FIFO
From already5chosen@yahoo.com

Show all headers | View raw


On Friday, December 4, 2015 at 4:56:10 AM UTC+2, jacko wrote:
> For a single thread to single thread FIFO, consider a tail circular list. This is a linked list where the tail points to the head as the next element. The pointer into the list points to the tail, so that tail insert is fast, and head remove is also fast. Head insert is possible but difficult to simply make thread safe.
> 
> So a tail insert takes 3 critical writes, and a head remove takes 1 critical write (atomic).
> 
> So a head read is valid when the write completes, and the tail pointer has not moved (indicates a tail write, overwriting the deletion from the circular list), and the read element is not a duplicate (as the last element can not be removed).
> 
> So a tail write is valid, by virtue of cancelling any head read, by overwrite. The process is to set up pointing to the head, moving the tail pointer to add in (voiding a head read), but prevent removal before completion, and then fix up the previously pointed to tail to point circularly to the tail.
> 
> So atomic reads and writes are required, but nothing further. And it is just 1:1 thread communication. As 2 writes or 2 reads will mess up. The fact that a common memory write location is shared by producer and consumer may slow certain systems, but will be very efficient on the same core fast threading with quick yield on fail. Duplicate finding is essential, and also indicates empty. A flush meta element is also a possibility maybe.
>

I don't see ho such thing can be potentially useful.
The part, omitted in your description, is a memory allocator.
For allocator I see two possibilities.

1. Flexible allocator that allocates variable-sized records from variable-sized pool. Or fixed-sized records from variable-sized pool. Or variable-sized records from fixed-sized pool. Such allocator is probably not look-free. But why bother with lock-free FIFO if at each put/get you using non-lock-free allocator?

2. Rigid allocator that allocates fixed-sized records from fixed-sized pool.
But then the whole solution has no more capabilities than simple circular buffer (a.k.a. array) of fixed-sized records managed by write pointer that is written only by producer and read pointer that is written only by consumer. And your linked circular list has plenty of disadvantages vs circular buffer, like taking more memory (for link in each record), being much slower and much much more complicated. Plus, circular buffer needs no fetch-and-add or CAS, only membar on some architectures and nothing on others.
Did I miss something?


> For 1:N the output can be sent to many 1:1 FIFO. The input multiplex then becomes the bottleneck of an N:N FIFO. Using say a 2:1 multiplex hierarchy on the N inputs, and having a reservation station for each input, along with a single atomic write 'I have input' location, a separate transit thread can pick up an element, and forward it, along with setting the reservation station null after. This may lead to duplicates too, but these have to be handle for the 1:1 output FIFO.
> 
> 1:1 input FIFO may be placed before the input multiplex for better thread spooling. And this would be more effective than many other multi contention FIFO structures.
> 
> Any questions?
> 
> An LGPL'ed piece of text (C) S. Jackson.

Back to comp.arch | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-03 18:56 -0800
  Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-03 19:22 -0800
  Re: Efficient lock free FIFO Ivan Godard <ivan@millcomputing.com> - 2015-12-03 19:32 -0800
    Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-03 19:36 -0800
      Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-03 19:40 -0800
  Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-03 21:46 -0800
    Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 00:12 -0800
      Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-04 13:59 -0800
        Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-04 14:06 -0800
        Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 15:36 -0800
          Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 15:40 -0800
        Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 15:53 -0800
          Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-05 13:36 -0800
            Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-05 13:39 -0800
  Re: Efficient lock free FIFO already5chosen@yahoo.com - 2015-12-04 01:59 -0800
    Re: Efficient lock free FIFO nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-04 10:28 +0000
      Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 07:08 -0800
      Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-05 17:55 -0800
        Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-05 17:59 -0800
        Re: Efficient lock free FIFO already5chosen@yahoo.com - 2015-12-06 04:03 -0800
          Re: Efficient lock free FIFO nmm@wheeler.UUCP (Nick Maclaren) - 2015-12-06 12:43 +0000
    Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 06:56 -0800
      Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-04 07:04 -0800
      Re: Efficient lock free FIFO already5chosen@yahoo.com - 2015-12-05 08:56 -0800
        Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-05 13:43 -0800
          Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-05 13:51 -0800
  Re: Efficient lock free FIFO (Something ...?) jacko <jackokring@gmail.com> - 2015-12-06 07:08 -0800
  Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-06 11:58 -0800
    Re: Efficient lock free FIFO "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-12-06 13:02 -0800
      Re: Efficient lock free FIFO jacko <jackokring@gmail.com> - 2015-12-06 13:37 -0800

csiph-web