Does an optimistic lock-free FIFO queue implementation exist?

后端 未结 5 1003
轻奢々
轻奢々 2021-01-02 05:40

Is there any C++ implementation (source codes) of \"optmistic approach to lock-free FIFO queues\" algorithm?

5条回答
  •  鱼传尺愫
    2021-01-02 06:17

    Here is my implementation of a lock-free FIFO.

    Make sure each item of T is a multiple of 64 bytes (the cache line size in the Intel CPUs) to avoid false sharing.

    This code compiles with gcc/mingw and should compile with clang. It's optimized for 64-bit, so to get it to run on 32-bit would need some refactoring.

    https://github.com/vovoid/vsxu/blob/master/engine/include/vsx_fifo.h

    vsx_fifo my_fifo;
    

    Sender:

    my_struct my_struct_inst;
    ... fill it out ...
    while (!my_fifo.produce(my_struct_inst)) {}
    

    Receiver:

    my_struct my_struct_recv;
    while(my_fifo.consume(my_struct_recv)) 
    { 
      ...do stuff...
    }
    

提交回复
热议问题