# wfqueue
**Repository Path**: uvicning/wfqueue
## Basic Information
- **Project Name**: wfqueue
- **Description**: No description available
- **Primary Language**: C++
- **License**: BSD-3-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-03-01
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README

# wfqueue.h [](https://travis-ci.org/Taymindis/wfqueue)
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++ | [](https://travis-ci.org/Taymindis/wfqueue)
VS x64/x86 | [](https://ci.appveyor.com/project/Taymindis/wfqueue)
#### support MPMC, MPSC and MCSP
## Example
### if c++
```c++
#include "wfqueue.h"
tWaitFree::Queue myqueue(sz);
// wrap in to thread
new ClassVal s(...);
tWaitFree::WfqEnqCtx enqCtx; // init 1 time in a thread only
tWaitFree::WfqDeqCtx 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
```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](https://github.com/Taymindis/lfqueue)