Is there a way to wait for a mutex (or similar object) to unlock without locking it afterwards?
In other words, is there a way to have the “reverse” of a condition variable, that will block the waiting thread until the locking thread releases the lock, but not block the waiting thread if the locking thread is not locked?
Is there a way in modern C++ to wait for a mutex (or similar object) to wait until unlock without locking it afterwards?
In other words, is there a way to have the “reverse” of a condition variable, that will lock the waited thread until the locking thread releases the lock but not lock the waited thread if the locking thread is not locked?
I have a main thread and a child thread that are both touching the same piece of data. For the most part I am using std::barrier
s to keep these two threads in sync and make sure one thread isn’t reading the data while the other is writing. There is one spot though were the child thread spins up a std::for_each(std::execution::par_unseq
that reads the data and does some heavy calculations while the main thread is off doing it’s own thing not touching the data except for one spot where it may or may not write some. I would like to be able to pause all of the reads on the threads when the main thread is writing but I don’t want each of the reads on the threads to block any of the other reads if there is no write going on.
IDK how many threads the for_each
might have spun off so I cannot use a barrier
here and I wouldn’t want to either way as I don’t want to wait if the read isn’t happening. It isn’t hard to do with a busy loop but I have been told using a busy loop in multi threaded code is bad form and that these std waits pause the threads and send signals on a OS level.
Is there a way in modern C++ to wait for a mutex (or similar object) to unlock without locking it afterwards?
In other words, is there a way to have the “reverse” of a condition variable, that will lock the waited thread until the locking thread releases the lock but not lock the waited thread if the locking thread is not locked?
I have a main thread and a child thread that are both touching the same piece of data. For the most part I am using std::barrier
s to keep these two threads in sync and make sure one thread isn’t reading the data while the other is writing. There is one spot though were the child thread spins up a std::for_each(std::execution::par_unseq
that reads the data and does some heavy calculations while the main thread is off doing it’s own thing not touching the data except for one spot where it may or may not write some. I would like to be able to pause all of the reads on the threads when the main thread is writing but I dont want each of the reads on the threads to block any of the other reads if there is no write going on.
IDK how many threads the for_each
might have spun off so I cannot use a barrier
here. It isn’t hard to do with a busy loop but I have been told using a busy loop in multi threaded code is bad form and that these std waits pause the threads and send signals on a OS level.