boostorg / boostorg/lockfree

a new lock-free queue

Open
#79 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
160
Forks
99
PR merge metrics
No merged PRs in 30d

Description

In theory, it is a queue without waiting, which supports multi-threaded reading and writing. Of course, the disadvantage is that the order of entering the queue may not be strongly ordered.

```cpp
template
class queue
{
private:
ring_buffer value_;

ring_buffer, N> readable_flag_{0};
ring_buffer, N> writable_flag_{0};

atomic writable_limit_;
atomic readable_limit_;
public:
queue() = default;
~queue() = default;

void push(const T & val)
{
size_t index = writable_limit_.fetch_add(1);

while (writable_flag_[index] != index / max_size())
;

value_[index] = val;
readable_flag_[index] = (index / max_size()) + 1;
}

void pop(T&val)
{
size_t index = readable_limit_.fetch_add(1);

while(readable_flag_[index] != (index / max_size()) + 1)
;

val = value_[index];
writable_flag_[index] = (index / max_size()) + 1;
}

size_t max_size() const
{
return N;
}

size_t size() const
{
size_t writable_limit = writable_limit_;
size_t readable_limit = readable_limit_;

return writable_limit > readable_limit ? writable_limit - readable_limit : 0;
}
};
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue provides only an inline C++ queue proposal and names no repository files or tests. Start by reading the proposal and the surrounding repository context to determine the intended integration and correctness requirements. Done is not defined in the issue, so scope and acceptance criteria need maintainer clarification.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.