condition-variable Questions

1

Solved

Some kernels provide a "flush" operation on semaphore to unblock all tasks waiting on a semaphore. For example, VxWorks has a semFlush() API that atomically unblocks all tasks pended on a specifie...
Helvellyn asked 2/3, 2020 at 22:20

1

An example from The Linux Programming Interface: In the producer threads, we would have code such as the following: static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static int avail = 0...
Swashbuckler asked 25/12, 2019 at 14:4

5

Solved

It's written in POSIX threads tutorial https://computing.llnl.gov/tutorials/pthreads/ that it is a logical error. my question is why it is a logical error? In my program i need to use these signa...
Kevin asked 4/4, 2011 at 9:35

3

Solved

For example the C++11 interfaces I am having a hard time figuring out when to use which of these things (cv, mutex and lock). Can anyone please explain or point to a resource? Thanks in advance.
Dysprosium asked 28/6, 2009 at 18:7

1

Solved

I am currently studying Google's Filament job system. You can find the source code here. The part that confuses me is this requestExit() method: void JobSystem::requestExit() noexcept { mExitRequ...
Concavity asked 10/6, 2019 at 4:52

1

Solved

My question is does std::promise notify the associated std::future through using a std::condition_variable? I search the source code of std::promise and found this website. But I didn't see std::...
Britzka asked 7/6, 2019 at 7:44

1

Solved

I am trying to understand the difference between spurious vs lost wakeup in case of a condition variable. Following is small piece code I tried. I understand that 'consumer' in this case could wake...

10

Solved

I’m reading up on pthread.h; the condition variable related functions (like pthread_cond_wait(3)) require a mutex as an argument. Why? As far as I can tell, I’m going to be creating a mutex just to...
Smalley asked 4/5, 2010 at 8:5

1

I am using code that runs on ARM (not Intel processor). Running c++11 code example (CODE A) from: http://www.cplusplus.com/reference/condition_variable/condition_variable/wait_for/ to test the wait...
Interradial asked 23/1, 2019 at 8:47

8

Solved

I am using C++11 and I have a std::thread which is a class member, and it sends information to listeners every 2 minutes. Other that that it just sleeps. So, I have made it sleep for 2 minutes, the...
Basrelief asked 2/10, 2018 at 14:43

2

Solved

I have yet to find a clear explanation of the differences between Condition and Event classes in the threading module. Is there a clear use case where one would be more helpful than the other? All ...
Mythopoeia asked 15/9, 2011 at 0:29

2

Solved

Among the options below, is there any correct way to deal with spurious wakeups when using conditional variables? 1) Put the wait(unique_lock_ul) into an infinite while loop, using a boolean uni...
Bashee asked 5/9, 2018 at 19:29

4

Solved

I'm trying to implement some cross-platform code in C++11. Part of this code implements a semaphore object using a std::condition_variable. When I need to do a timed wait on the semaphore, I use wa...
Marsha asked 23/6, 2018 at 21:42

3

Solved

Consider the following codesnippet: #include <iostream> #include <condition_variable> #include <chrono> #include <mutex> int main () { std::mutex y; std::condition_varia...
Copenhaver asked 15/8, 2018 at 12:49

2

Solved

I tried including std::condition_variable as a class member, and got a lot of compilation errors when passing an object of this class to a std::thread. I cut down all the other code from my actual ...
Kathikathiawar asked 28/6, 2018 at 16:49

1

I'm working on an application where I currently have only one condition variable and lots of wait statements with different conditions. Whenever one of the queues or some other state is changed I j...
Logical asked 29/5, 2018 at 9:18

5

I'm trying to implement an multi-thread job, a producer and a consumer, and basically what I want to do is, when consumer finishes the data, it notifies the producer so that producer provides new d...
Kasey asked 7/5, 2018 at 14:17

0

In the chapter 6 of C++ Concurrency in Action, it implements a thread-safe queue. Here is the complete code. But I find there may be something wrong with its use of condition variable. std::uniqu...
Dacoity asked 6/5, 2018 at 3:19

4

I have the following code, which deadlocks on the commented lines. Basically f1 and f2 run as individual threads in the program. f1 expects i to be 1 and decrements it, notifying the cv. f2 expects...
Pigeontoed asked 3/4, 2018 at 5:17

4

Solved

As it is said that Mutex are needed to protect the Condition Variables. Is the reference here to the actual condition variable declared as pthread_cond_t OR A normal shared variable count whose va...
Malonylurea asked 18/5, 2012 at 7:8

4

Solved

The reference I'm using explains the two in the following way: wait_for "blocks the current thread until the condition variable is woken up or after the specified timeout duration" wait_until "bl...
Longshoreman asked 30/10, 2012 at 15:25

3

Solved

First a little context: I'm in the process of learning about threading in C++11 and for this purpose, I'm trying to build a small actor class, essentially (I left the exception handling and propaga...

1

Solved

I stumbled over the following code in Bjarne Stroustrup's "The C++ Programming Language, 4th Edition" on page 119: queue<Message> mqueue; condition_variable mcond; mutex mmutex; void consum...
Compilation asked 31/7, 2017 at 12:23

1

Solved

I'm confused about conditions_variables and how to use them (safely). In my application I've a class that makes a gui-thread but while the gui is constructed by the gui-thread, the main thread need...
Achitophel asked 10/5, 2017 at 16:30

1

Solved

I'm trying to launch new threads as soon as work in previous worker_thread has started, but maybe ended or not. I've replaced started and ended work with time delays. My code is: #include <iost...
Sthenic asked 1/4, 2017 at 12:32

© 2022 - 2024 — McMap. All rights reserved.