31 questions
1
vote
0
answers
83
views
Waking up parallel threads waiting on a conditional variable
I'm a bit confused with an example of std::conditional_variable.
I have several waiting threads, and would like to use notify_all() to wake up all of them at the same time.
I have modified code from ...
2
votes
2
answers
173
views
C, Using 2 threads with mutex and conditional variable to print A0B1A2B3A4B5A6B7A8B9
So I have this lab problem where I need to use 2 threads with mutex and cond var to print the title pattern. The pattern is stored in an array of char, and there's a global keeping track of which ...
-3
votes
1
answer
115
views
Can a unique_lock and a normal lock cause together a dead-lock?
I'm using unique_locks and normal lock to lead the threads. I try to interlink the threads, so they don't loose too many cycles and work together and not separately.
I don't know, if my code can ...
0
votes
0
answers
131
views
How to catch exceptions by std::condition_variable::wait_for()
For some reason, my project is always crashing when I call std::condition_variable::wait_for(). Unfortunately, this project's crash handler goes out of its way to be as unhelpful as possible, but it ...
0
votes
2
answers
141
views
Synchronize three Threads in C++ one after the other
This is in continuation to this really nice one: https://stackoverflow.com/a/33500554/22598822. That post was for the sequence (t1 & t2) --> t3. Let's say I have a program running, and there ...
2
votes
0
answers
86
views
Synchronizing simulation output generation and reading using producer and consumer threads in C++
Beginner level synchronization question here.
There’s a lot of material on how to implement producer-consumer synchronization. I really did try all variations that I thought made sense, but none seems ...
0
votes
0
answers
32
views
pthead_cond_wait wake up thread case crash
I use an ConcurrentQueue in my project.But sometimes I meet crash caused by this ConcurrentQueue.I do not have any idea about this crash so I want to get some help.This code show my ConcurrentQueue
#...
0
votes
1
answer
58
views
How pritnOdd thread is able to proceed in below program to print natural numbers by even and odd threads?
Below programs works fine. But My doubt is very beginning both threads (printEven and printOdd) is waiting for signal on conditional variable( statement pthread_cond_wait(&cond, &mutex);) then ...
1
vote
0
answers
63
views
How can I run a detached thread that is waiting for a conditional variable in a loop?
I've got a very time critical simulator that is supposed to run as fast as humanly possible. I tried to increase the data throughput by distributing every data frame to multiple worker threads. To ...
6
votes
1
answer
695
views
Does condition variable notify_one keep trying until it reaches thread awaiting with a positive predicate?
I'm testing edge cases with std::condition_variable and I tested scenario to starve one thread.
Scenario is that there are 99 producers and only one consumer, all of them working on 1 queue with max ...
3
votes
1
answer
403
views
c++ segmentation fault using condition_variable with the -static linkage flag
I compiled and linked this simple program using g++ in a Raspberry Pi 4 running on the ARMv8-A.
compiler: g++ -Wall -O0 -g3 -std=c++11 -c Main.cpp
linker: g++ -static -o "bugTest.elf" ./Main....
0
votes
1
answer
114
views
Why does modifying condition for condition variable require owning the mutex?
Consider this case (which is the standard usage in cppreferences):
std::atomic<bool> condition(false);
thread 1:
lock
// check condition the last time before waiting
if (condition == true) { ...
4
votes
2
answers
787
views
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 ...
0
votes
1
answer
75
views
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 ...
0
votes
3
answers
570
views
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 ...
0
votes
1
answer
103
views
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 ...
-1
votes
1
answer
2k
views
unique_lock.lock() causes abort in C++
I am learning C++ threads and i don't understand unique_lock mechanism very well. I reed This Link with Conditional variable, and more examples here but still I have my confusions:
1- So my question ...
1
vote
0
answers
829
views
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 ...
-1
votes
2
answers
117
views
How immediately pause a thread?
Assum have two thread that one of them has more priority and they are running on same core (single core),
I only want work just one thread at same time.(maybe you say that is not threading paradigm , ...
0
votes
1
answer
130
views
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 ...
0
votes
1
answer
538
views
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 ...
2
votes
3
answers
120
views
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 ...
2
votes
1
answer
845
views
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 ...
0
votes
0
answers
69
views
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 ...
0
votes
1
answer
106
views
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 ...
0
votes
0
answers
43
views
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 ...
0
votes
1
answer
107
views
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 ...
0
votes
1
answer
50
views
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 ...
6
votes
1
answer
1k
views
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(&...
0
votes
1
answer
831
views
How to wait and notify at the same time - conditional variable?
So I want to wait until ender has started waiting here is what basically:
std::condition_variable avalanche;
std::mutex mutex;
std::cout << "avalanche" << ...
7
votes
4
answers
16k
views
POSIX C Threads. pthread_cond_t example. Doesn't work as expected
I wrote a wrote a program and it doesn't work as I expect it to.
I have two threads: thread triggers func and anotherThread triggers anotherFunc. What I wanted to do is when cont reaches value 10 in ...