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


Groups > comp.arch > #31405

Efficient lock free FIFO

Newsgroups comp.arch
Date 2015-12-03 18:56 -0800
Message-ID <ec9545f0-93a8-4672-8f59-695eee864d30@googlegroups.com> (permalink)
Subject Efficient lock free FIFO
From jacko <jackokring@gmail.com>

Show all headers | View raw


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.

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 — 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