condition-variable Questions

1

Solved

I've looked into the VC++ implementation of std::condition_variable(lock,pred), basically, it looks like this: template<class _Predicate> void wait(unique_lock<mutex>& _Lck, _Pred...
Submultiple asked 26/2, 2017 at 16:2

2

Accoding to cppreference.com: The thread that intends to modify the variable has to acquire a std::mutex (typically via std::lock_guard) perform the modification while the lock is he...
Associationism asked 26/1, 2017 at 5:7

2

Solved

For simplicity, let's assume that we have only one conditional variable to match a single condition that is reflected by a boolean. 1) Why does std::condition_variable::wait(...) locks the mutex a...
Impudence asked 20/1, 2017 at 18:13

2

I am trying to wait for a specific condition, and I would like advice as to how this is done best. I have a struct that looks like this (simplified): type view struct { timeFrameReached bool Row...
Connote asked 19/1, 2017 at 21:2

3

Solved

I am using a std::condition_variable combined with a std::unique_lock like this. std::mutex a_mutex; std::condition_variable a_condition_variable; std::unique_lock<std::mutex> a_lock(a_mutex...
Rancid asked 13/11, 2016 at 18:59

3

Solved

I am trying to understand what happens to a mutex when it is used in a condition variable. In the following example, taken from cppreference int main() { std::queue<int> produced_nums; st...
Hosanna asked 22/10, 2012 at 20:33

1

Solved

In our Android app, we have UI component and core C++11 module. A thread is running based on std::chrono::system_clock::time_point, such as below: while(this->m_ConditionVariable.wait_until(loc...
Sulfate asked 29/11, 2016 at 12:7

1

Solved

This is a follow-up to Can C++11 condition_variables be used to synchronize processes?. Can std::condition_variable objects be used as counting semaphores? Methinks not because the object seems b...
Cento asked 31/10, 2016 at 2:3

2

Solved

I'm trying to learn about C++11's std::condition_variable. I've read the articles at cppreference.com and cplusplus.com as well as C++0x has no semaphores? How to synchronize threads?. My question...
Stickler asked 30/10, 2016 at 20:23

1

Solved

Consider the following simplistic example of condition variables: bool pause = true; boost::mutex::scoped_lock lock(m_mutex); while (!pause) cv.wait(lock); and boost::mutex::scoped_lock lock(...
Barnwell asked 22/9, 2016 at 6:59

3

I am trying to use a thread within my class, then the thread needs to use a condition_variable, and the condition variable will be blocked until a predicate be changed to true. The code looks like ...
Ridotto asked 19/9, 2016 at 4:7

3

Solved

As it turns out, condition_variable::wait_for should really be called condition_variable::wait_for_or_possibly_indefinitely_longer_than, because it needs to reacquire the lock before really timing ...
Trepang asked 8/8, 2014 at 1:7

4

Solved

When using timed_wait on a boost::condition_variable with a duration, will the wait condition time out after the duration even if the user (or ntp) changes the system time? E.g., boost::posix_tim...
Teleplay asked 7/12, 2010 at 20:10

1

Solved

I am trying to add a condition_variable to handle threads, but get a compilation error at this line: this->cv.wait(lk, []{return this->ready;}); Looks like the for the variable this->read...
Disjunctive asked 26/7, 2016 at 16:57

2

Solved

Assuming no undefined behaviour occurs, no deadlocks occur, mutexes are locked and unlocked in the correct order by the correct threads the correct number of times, non-recursive mutexes are not ...
Longer asked 13/5, 2016 at 8:51

2

Solved

I am not sure if I really understand why std::condition_variable needs a additional std::mutex as a parameter? Should it not be locking by its self? #include <iostream> #include <conditio...
Lymanlymann asked 12/5, 2016 at 7:50

3

If std::condition_variable can be signaled due to the spurious wakeups (and we can't be sure that the condition we need is really satisfied), why do C++ Standard Library provide the overloads of wa...
Salaried asked 26/1, 2016 at 11:30

3

Solved

I need to be clarified how lock and condition_variable work. In the -slightly modified- code from here cplusplusreference std::mutex m; std::condition_variable cv; std::string data; bool ready = ...
Obmutescence asked 10/8, 2015 at 7:11

2

In the documentation for std::condition_variable, there is an overload of wait() taking as argument a predicate function. The function will wait until the first wake_up at which the predicate funct...
Dissipated asked 13/11, 2015 at 12:16

1

Solved

Consider the following example. std::mutex mtx; std::condition_variable cv; void f() { { std::unique_lock<std::mutex> lock( mtx ); cv.wait( lock ); // 1 } std::cout << "f()\n"; }...
Wendel asked 6/10, 2015 at 19:25

1

Solved

I've tested this scenario in some environments, and I got the following flow: However, from the man pages ( http://linux.die.net/man/3/pthread_cond_wait ) or ( http://linux.die.net/man/3/pthread...
Demagogy asked 10/9, 2015 at 10:43

4

Solved

I'm learning about C++11 concurrency, where my only prior experience with concurrency primitives was in Operating Systems class six years ago, so be gentle, if you can. In C++11, we can write std...

2

We were working on our audio player project on mac and noticed that the power usage was so high (about 7x that of google chrome doing the same workload.) I used xcode's energy profiling tool, one ...
Credent asked 27/3, 2015 at 20:58

1

Solved

I'm trying out Windows support for Condition Variables today (as provided by Microsoft for Windows Vista and later). To initialize a condition variable, I call InitializeConditionVariable(), which ...
Consecrate asked 10/3, 2015 at 23:27

1

Solved

my problem looks like this: I've got a observer which holds a std::condition_variable and a std::mutex, my worker thread objects have a pointer to the observer. Each time a worker thread finished ...
Salenasalene asked 30/11, 2014 at 21:42

© 2022 - 2024 — McMap. All rights reserved.