Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
63 views

Managing Worker Thread Wake-Up in C++: Separate vs. Shared Condition Variables?

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
46 views

Synchronization using condition_variable

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
112 views

Why does using separate lock_guard for cv wait and pop() cause a segmentation fault?

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
68 views

Why is my Timer class not executing when started consecutively with no delay?

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
113 views

(c++ thread and condition_variable) Could this program never end forever?

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
101 views

Why is the condition_variable in the thread pool not woken up?

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
95 views

C++ condition variable doesn't block the thread on wait_until() using the time_poin::max()?

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
80 views

How to prevent worker threads from idling until next condition variable notify

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
  • 15.2k
1 vote
1 answer
140 views

Why is the output of this code incorrect?

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
44 views

What is the return value of `wait_until` in case of triggered or spurious wakeup, when timeout was reached?

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,911
1 vote
1 answer
102 views

How to correctly use condition_variable and time_wait/timed_join in threads?

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.6k
1 vote
1 answer
133 views

Question about condition_variable, why condition_variable is paired with mutex [duplicate]

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
60 views

Producer-consumer problem with queue and semaphore

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
0 votes
0 answers
77 views

Why does my producer-consumer program using pthread_cond_signal get stuck?

I am writing a producer-consumer program using pthread in C. The program should produce and consume items up to a limit n. However, my program usually gets stuck quickly when n = 1 and n = 2. To be ...
Makise Kurisu's user avatar
0 votes
0 answers
22 views

How many objects of mutex, semorphore or condition variables could a process initiate up to?

It's obvious to me that virtual address space of a process turns out to be limit the number of objects of futex, mutex, semorphore or condition variables may never be created up to. Is there other ...
Y.Z's user avatar
  • 678

15 30 50 per page
1
2 3 4 5
51