Linked Questions
27 questions linked to/from Mutex example / tutorial?
-2 votes
1 answer
182 views
Limiting mutex scope using blocks in header [duplicate]
I have a class that has its own worker thread, and some of the member variables of the class is shared between the main thread and the worker. How can I use a mutex to lock only the member variables ...
1020 votes
37 answers
701k views
Difference between binary semaphore and mutex
Is there any difference between a binary semaphore and mutex or are they essentially the same?
1033 votes
10 answers
534k views
What is a mutex?
A mutex is a programming concept that is frequently used to solve multi-threading problems. My question to the community: What is a mutex and how do you use it?
164 votes
13 answers
158k views
When should we use mutex and when should we use semaphore
When should we use mutex and when should we use semaphore ?
58 votes
6 answers
56k views
Do I need a mutex for reading?
I have a class that has a state (a simple enum) and that is accessed from two threads. For changing state I use a mutex (boost::mutex). Is it safe to check the state (e.g. compare state_ == ...
45 votes
2 answers
29k views
boost scoped_lock vs plain lock/unlock
I'm going to use boost::mutex from boost/thread/mutex.hpp. There are several ways to lock/unlock mutex: with scoped_lock, unique_lock, lock_guard, mutex's member functions ::lock() and ::unlock() and ...
4 votes
8 answers
9k views
Threading on both Windows and Linux
I have seen tutorials on the internet for making multithreaded applications in C++ on Windows, and other tutorials for doing the same on Linux, but not for both at the same time. Are there functions ...
7 votes
4 answers
14k views
Can someone Explain Mutex and how it is used?
I read a few documents about Mutex and still the only Idea I have got is that it helps preventing threads from accessing a resource that is already being used by another resource. I got from Code ...
5 votes
5 answers
3k views
To Mutex or Not To Mutex?
Do I need a mutex if I have only one reader and one writer? The reader takes the next command (food.front()) from the queue and executes a task based on the command. After the command is executed, it ...
2 votes
2 answers
3k views
Mutex lock on separate classes
What is the correct use of a Mutex? How do I know what it is protecting? Does it stop all threads from running for the locked period? For example I have a singleton that contains a list of objects. ...
2 votes
6 answers
3k views
How can I synchronize three threads?
My app consist of the main-process and two threads, all running concurrently and making use of three fifo-queues: The fifo-q's are Qmain, Q1 and Q2. Internally the queues each use a counter that is ...
3 votes
2 answers
2k views
Multi Threading - Peterson's algorithm not working
Here I use Peterson's algorithm to implement mutual exclusion. I have two very simple threads, one to increase a counter by 1, another to reduce it by 1. const int PRODUCER = 0,CONSUMER =1; int ...
1 vote
4 answers
3k views
Asynchronous Sleep in Visual C++/Cli, How to create a of X milliseconds to call a function without making the GUI stops too
In the title is pretty clear, I just need to know if there's a way to Sleep for some miliseconds and then call a function without stopping the GUI. The way that I do now is just adding Sleep(3000); ...
1 vote
2 answers
1k views
Boost threading/mutexs, why does this work?
Code: #include <iostream> #include "stdafx.h" #include <boost/thread.hpp> #include <boost/thread/mutex.hpp> using namespace std; boost::mutex mut; double results[10]; void doubler(...
0 votes
2 answers
1k views
threading.h:10:24: fatal error installation error
Fairly unknowledgable linux (ubuntu 14.04) user here. I'm trying to install a bioinformatics program called Bowtie2 - I get this error and not sure where it's coming from. They did quote this on their ...