Questions tagged [conditional-variable]
18 questions
5
votes
1 answer
Why does this use of Condvar wait and notify not deadlock?
https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html
use std::sync::{Arc, Mutex, Condvar};
use std::thread;
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair2 = Arc::clone(&pair);
// Inside of our lock, spawn a new…

Wynell
- 633
- 1
- 8
- 15
4
votes
2 answers
sync.Cond with Wait method in Go
I read unusual case in documentation sync.Cond:
Because c.L is not locked while Wait is waiting, the caller typically
cannot assume that the condition is true when Wait returns. Instead,
the caller should Wait in a loop:
c.L.Lock()
for…

QuickDzen
- 247
- 1
- 11
2
votes
3 answers
Why isn't pthread_cond_signal() being called?
So I am trying to understand pthread_cond_t variables, but the problem is often sometimes pthread_cond_signal()/pthread_cond_broadcast() doesn't work and the sleeping threads are not woken up, leading to a deadlock in my code.
Is there a problem in…

Cardinal
- 73
- 5
2
votes
1 answer
C++ Timer - Start & Stop works - Restart doesn't
I am having a trouble exiting a thread using a Restart function. When calling Stop it exits the thread, but Restart which calls Stop and then Start right after - doesn't exit the thread -> calls Start and creates a new thread.
Thanks. Any help would…

rozfet
- 23
- 2
1
vote
0 answers
Defining different values to an enum according to a condition in python
I'm dealing with an "apparently" simple problem with enums in Python that i cannot figure out how to solve. I just need to load different values for an enum in different environments (dev and prod). Ex:
in dev environment I`d like to define:
from…

Maurício Silva
- 53
- 4
0
votes
1 answer
How to solve deadlock(waiting for singal from a failed test)
I have two goroutines which are two TestXxx functions during the testing. I use a conditional variable to synchronize these goroutines. However, once one of them fails the test while the other one is waiting for the signal. Here comes a deadlock.…

WeiAnHsieh
- 33
- 4
0
votes
3 answers
How many conditoinal variables should be used in producer-consumer problem?
I am currently learning multi-threading in C++. I have a question about the conditional variable.
If I have such code:
std::condition_variable cvS;
std::condition_variable cvR;
std::condition_variable cv;
std::mutex gMtx;
int countm = 0;
void…

Kevin eyeson
- 375
- 4
- 8
0
votes
1 answer
Producer consumer using boost::interprocess_confition with boost:interprocess shared memory. Consumer dominates 100%
Just making a simple example because I am having issues with a more complex usecase and want to udnerstand the base case before spending too much time in trial and error.
Scenario:
I have two binaries that supposedly takes turns incrementing a…

Serj
- 51
- 1
- 6
0
votes
1 answer
Why can't i add to the OBJ's but i can add to the CFLAGS/SRC's in a MAKEFILE
I want two Makefile targets which both create the same targetfile but with some bonus files added to the normal files in the bonus rule (all files inside the final .a though).
Which in itself is pretty easy, but i want both rules to not relink.
By…

ludmuterol
- 5
- 1
- 5
0
votes
1 answer
Showing the unlock from std::condition_variable::wait
I've read from https://en.cppreference.com/w/cpp/thread/condition_variable/wait that wait() "Atomically unlocks lock". How do I see this via std::cout? I am trying to understand conditional variables better on what they're actually doing. I've wrote…

davidj361
- 147
- 7
0
votes
0 answers
C++ Timer - Start & Stop works, Restart doesn't
I am having a trouble exiting a thread using a Restart function. When calling Stop it exits the thread, but Restart which calls Stop and then Start right after - doesn't exit the thread -> calls Start and creates a new thread.
Thanks. Any help would…

poorharambe1
- 1
- 1
0
votes
1 answer
Progress Bar Causes Program to Halt and Lock, How Can I Fix It?
Below is the current code that I am working with. When I comment out the code to run the progress_bar function, code works perfectly as expected with the mandelbrot printed out into a seperate image file. Yet for whatever reason, when I try to…

Kitso
- 51
- 5
0
votes
0 answers
Cross-talk of condition_variables signal and how to avoid it
I'm using the mutex and condition_variable pair to implement mult-threaded processing. I have read examples and solid explanations like this and that. However, I do not understand why separate variables trigger each other. For example,
mutex alert0,…

Jason M
- 411
- 5
- 19
0
votes
1 answer
Last notify_all isn't triggering last conditional_variable.wait
What I'm Trying To Do
Hi, I have two types of threads the main one and the workers where the workers are equal to the number of cores on the CPU, what I'm trying to do is when the main thread needs to call an update I set a boolean called Updating…

Pedro S
- 3
- 2
0
votes
1 answer
How to Create a Complex Conditional Variable on R
I have four binary yes/no variables.
I want to create a combined variable that is dummy coded in the following manner:
0 if participants say "Yes" to all 4 Variables (4/4)
1 if participants say "Yes" to 3 out of the 4 Variables (3/4)
2 if…

Heshani
- 13
- 3