All Questions
Tagged with concurrency c++
1,248
questions
0
votes
1
answer
36
views
c++ concurrency problem using semaphore: print in order
As an c++ concurrency exercise, I want to print letters A B C in that order, using semaphore. Here's my code:
binary_semaphore sem[] = { binary_semaphore(1), binary_semaphore(0), binary_semaphore(0) };...
0
votes
0
answers
44
views
C++ main thread polling and blocking, termination on signal
I have a main thread which should do some work every N seconds (20 in this case) and wait/block/suspend in-between. However, at the same time, I want the application to stop correctly on a SIGTERM/...
0
votes
1
answer
62
views
Guarding tests against exit/death
I'm using googletest to test multi-threading code with std::thread. In broken code, it often happens that a std::thread is destroyed before the thread has joined, causing a program termination. ...
1
vote
0
answers
53
views
How to reduce cache miss in SPSC queue pop function?
I am working on optimizing a Single Producer Single Consumer (SPSC) queue in C++. The following is the miniman reproducible example for my implementation:
#include <atomic>
#include <cstddef&...
1
vote
0
answers
28
views
Why does Folly's `rcu_domain.retire(list_node* node)` require non-blocking `half_sync`?
I've been examining Folly's implementation of RCU.h, particularly how half_sync is used within the retire function. The relevant snippet is shown as follows:
void retire(list_node* node) noexcept {
//...
0
votes
1
answer
73
views
How can I formally verify the correctness of my WaitGroup implementation in C++?
Description
I've implemented a WaitGroup in C++ assuming that:
user must ensure that the counter value does not drop below zero.
WaitGroup can be reused.
Below is my code:
class WaitGroup {
public:
...
0
votes
1
answer
102
views
Is Intel TBB concurrent vector of doubles lock-free?
I am writing C++ multithreaded code using GCC C++20 on Intel Broadwell XEONs or AMD EPYC 7551s, Intel TBB, and Pagmo2 libraries for optimization problems. If I declare concurrent_vector<double> ...
1
vote
1
answer
82
views
memory_order_release and seq_cst synchronization
I remember that C++ concurrency in action book mentions that memory_order_release synchronizes with seq_cst so how can hardware / compiler reorder instructions of this?
This image reference is - https:...
1
vote
1
answer
81
views
C++ Concurrency - memory_order_acquire [duplicate]
#include <atomic>
#include <thread>
std::vector<int> queue_data;
std::atomic<int> count;
void populate_queue()
{
unsigned const number_of_items=20;
queue_data.clear();
...
0
votes
1
answer
62
views
Thread-safety problem of a thread pool implementation in listing 9.8 of C++ Concurrency in Action
I'm reading C++ Concurrency in Action, 2ed. And the writer showed an implementation of thread pool that uses work stealing as follows:
// Listing 9.7 Lock-based queue for work stealing
class ...
0
votes
0
answers
82
views
Why is my OpenMP based Code not getting any speedup?
I am trying to fill in "valid points" into a vector of vectors and I do it with the use of local vector of vector which I then merge. I also write the time measuring strategy for ...
0
votes
0
answers
38
views
Why do we need this additional check in this concurrent queue implementation?
Working through a textbook which suggests the following implementation for a concurrent queue. I am wondering why the two if statements, which are highlighted in the code, are necessary. After the ...
1
vote
1
answer
129
views
Websocket boost/beast example with client/server
Maybe somebody can provide simple example(or references) on how to setup client and server using websocket from boost/beast library? I need an example on how to handle input message on server and ...
0
votes
1
answer
60
views
What the fundamental difference between an async code polling a cancellation token and registering a callback to be executed when the caller requests?
I'm watching (not for the first time) Working with Asynchrony Generically: A Tour of C++ Executors (part 1 and 2), which is about P2300.
With respect to cancellation support, Eric Niebler says that ...
2
votes
1
answer
97
views
Any real-life examples for memory_order_seq_cst?
It seems Release-Acquire ordering is enough in most cases, so is there any real-life examples where you can only use memory_order_seq_cst?(and Ordering::SeqCst, because rust shares same memory order ...