GithubHelp home page GithubHelp logo

kuan-li / wfqueue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from taymindis/wfqueue

0.0 1.0 0.0 86 KB

wait free FIFO queue, easy built cross platform(no extra dependencies needed)

License: BSD 3-Clause "New" or "Revised" License

C++ 79.35% C 14.00% CMake 6.65%

wfqueue's Introduction

wfqueue logo

wfqueue.h Build Status

c/c++ FIFO wait-free queue, easy built cross platform(no extra dependencies needed)

Guarantee thread safety memory management, and it's all in one header only, as fast as never wait.

All Platform tests

GCC/CLANG/G++/CLANG++ | Build Status

VS x64/x86 | Build status

support MPMC, MPSC and MCSP

Example

if c++

#include "wfqueue.h"


tWaitFree::Queue<MyVal> myqueue(sz);

// wrap in to thread
new ClassVal s(...);
tWaitFree::WfqEnqCtx<MyVal> enqCtx; // init 1 time in a thread only
tWaitFree::WfqDeqCtx<MyVal> deqCtx; // init 1 time in a thread only


// wrap in to thread
// please use enq to guarantee enqueue.
if(myqueue.tryEnq(s, enqCtx)) {
	printf("%s\n", "Enq Done");
} else {
	printf("%s\n", "queue is full, please try again to re-enqueue ");
}

// wrap in to thread
// please use deq to guarantee dequeue.
if(myqueue.tryDeq(s, deqCtx) {
  s->do_op();
}

if c

#include "wfqueue.h"

// Fixed size of queue
wfqueue_t *q = wfq_create(sz); 
wfq_enq_ctx_t enq_ctx = wfq_init_enq_ctx(); // init 1 time in a thread only
wfq_deq_ctx_t deq_ctx = wfq_init_deq_ctx(); // init 1 time in a thread only
// wrap in to thread
ClassVal *s = malloc(sizeof(ClassVal);

// wfq_enq_must for guarantee enqueue
wfq_enq_must(q, s, &enq_ctx);

// wrap in to thread
// wfq_deq_must for guarantee dequeue
s = (ClassVal*)wfq_deq(q, &deq_ctx); // return NULL if no val consuming

if(s) {
  s->do_op();

  free(s);
}

wfq_destroy(q);

Build

include header file in your project

Comparison with MoodyCamel/ConcurrentQueue

4 Concurrent Threads

Type WFQUEUE (c++) ms WFQUEUE (c)ms MOODYCAMEL (ms) INPUTS PER THREAD
MPMC 389.0 370 393.9 1,000,000 * 4
MPSC 494.50 600 684.0 1,000,000 * 4
MCSP 252.70 290.5 175.7 1,000,000 * 4

8 Concurrent Threads

Type WFQUEUE (c++) ms WFQUEUE (c)ms MOODYCAMEL (ms) INPUTS PER THREAD
MPMC 657.20 642.2 517.90 1,000,000 * 8
MPSC 1140.50 1420 1471.8 1,000,000 * 8
MCSP 247.80 245.2 253.2 1,000,000 * 8

8 Concurrent Threads with wfqueue(2 capacity only), create a small queue

Type WFQUEUE (c++) ms WFQUEUE (c)ms MOODYCAMEL (ms) INPUTS PER THREAD
MPMC 499 496 517.90 1,000,000 * 8
MPSC 1718 1700 1471.8 1,000,000 * 8
MCSP 403 360 253.2 1,000,000 * 8

Next feature target

No pre allocated size needed, it will expand itself (expandable size)

You may also like lock free queue FIFO

lfqueue

wfqueue's People

Contributors

taymindis avatar cdgwoon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.