Skip to main content
1 vote
1 answer
128 views

I have two threads where one thread needs to wait for the other thread to complete its task. To solve this problem I decided to use std::condition_variable. My question is, should the thread that is ...
Joe J's user avatar
  • 1,349
4 votes
3 answers
236 views

An example of producer and consumer threads is usually given. But this can be done with two semaphores. Why do we need condition variables then? Example with pthread library: // write thread while(1) {...
FlameWare's user avatar
1 vote
0 answers
82 views

I have a queue of worker thread IDs in C++, and a coordinator thread wakes each thread in order. The woken thread then interacts with the coordinator thread to perform some work. Once done, the ...
Utkarsh Munjal's user avatar
1 vote
1 answer
50 views

There is such an interesting little code (I'll take the most important thing, since my project is quite large void RunForever(int time_out) { int criticalSize = 3; ...
user29207775's user avatar
2 votes
3 answers
129 views

I created a Packets class to synchronize data processing between consumers and producers. My design uses separate locks for the condition variable (cv wait) and the operation of popping packets from ...
user3191398's user avatar
0 votes
0 answers
79 views

I have a custom Timer class in C++ that uses std::async to run a timer in a separate thread. The problem I'm facing is that when I call start() on the same Timer object consecutively with no delay, ...
sleepyhead's user avatar
2 votes
1 answer
132 views

I think the source code below may not end forever. Assume that all waiter threads have entered the wait state. After that, waker call notify_all() One thread, t1, wakes up and does something. And ...
user19800684's user avatar
0 votes
0 answers
110 views

I wrote a thread pool by myself, and the Result class is used to obtain the calculation results of the thread pool tasks. Initially, I used a simple semaphore mechanism to implement thread ...
牛牪犇's user avatar
0 votes
1 answer
123 views

The below code doesn't block the thread and it gets into an infinite loop and keep printing Waiting... Waiting... My idea is, the thread should block on the max() time and when it's set to now(), it ...
Seektech's user avatar
0 votes
1 answer
108 views

Let's just say I have a bunch of worker threads waiting until there are tasks in the queue. Generally you have the producer call the produce function, and then notify_one so that the worker thread can ...
Zebrafish's user avatar
  • 16.3k
1 vote
1 answer
149 views

Normally, the output should always be 200.But the output of "totalMoney" sometimes a number less than 200. What is the issue here and how to correct it? #include <condition_variable> #...
yongjay's user avatar
  • 11
1 vote
1 answer
69 views

I have a question for the "first" version of std::condition_variable::wait_until, that is, the one without the condition predicate parameter, which should return std::cv_status value. The CV ...
Ethouris's user avatar
  • 1,921
1 vote
1 answer
144 views

I'm experiencing a wierd behaviour with thread. I isolated the problem in this simple example: #include <iostream> #include <boost/thread.hpp> #define SLEEP_DURATION 1000 static boost::...
jpo38's user avatar
  • 21.9k
1 vote
1 answer
171 views

I have been learning std::condition_variable recently and there is just some question that I cannot understand. Cppreference and many other tutorials give example like this: std::mutex m; std::...
lustfully's user avatar
0 votes
0 answers
70 views

In Stroustrup's book The C++ Programming Language, there is a code example that demonstrates the use of condition variables: class Message { // object to be communicated //... }; queue<...
Mathai's user avatar
  • 839

15 30 50 per page
1
2 3 4 5
51