Questions tagged [mutex]

A mutex ("mutual exclusion") is a mechanism to ensure integrity when the same data or resource is accessed (in particular, changed) concurrently from several threads.

A mutex ("mutual exclusion") is a mechanism to ensure integrity when the same data or resource is accessed (in particular, changed) concurrently from several threads.

Usually when the term mutex is used, it refers to a synchronisation primitive functionally identical to a binary semaphore. As OS-level synchronisation is often rather expensive due to context switching, busy-wait solutions based on atomic operations (e.g. mutex or critical section) exist.

See also:

4640 questions
2
votes
1 answer

AppMutex with Inno Setup: Wait few seconds before prompt

Using Inno Setup together with an AppMutex works fine - when the setup is started and the mutex still exits, the user is prompted to close this application. But following question: Is there a way to tell Inno Setup to wait 2-3 seconds if the program…
ab-tools
  • 528
  • 5
  • 18
2
votes
1 answer

Which thread owns the associated mutex after pthread_cond_broadcast?

This question concerns the pthread API for Posix systems. My understanding is that when waiting for a conditional variable, or more specifically a pthread_cond_t, the flow goes something like this. // imagine the mutex is named mutex and the…
William Rosenbloom
  • 2,506
  • 1
  • 14
  • 37
2
votes
8 answers

Pthreads- 1 lock, 2 unlocks

If I understand correctly, then foo1() fails to unlock &private_value_. As a result, foo2()'s thread_mutex_lock does not work since foo1() never released it. What are the other consequences? int main ( ... ) foo1(); foo2(); return 0; } foo1() { …
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
1 answer

Where to define a mutex in a multithread program and what is the difference

I'm new to multi-threads programming and I got confused about where to declare mutex. I got the idea of mutex, lock/unlock by googling a lot. But I still don't know where I need to declare the pthread_mutex_t variable, and what's the difference.…
2
votes
2 answers

what problems can calling std::list/vector/map/deque::empty() outside mutex scope cause?

Consider the following code snippet: thread 1: while (true) { task = fetch_task(); { lock_guard lock(my_mutex); // modify content of my_list my_list.push_back(task); } } thread 2: while (true) { if…
frans
  • 8,868
  • 11
  • 58
  • 132
2
votes
3 answers

Increasing concurrency in producer consumer

I am solving a specific kind of producer-consumer which goes as follows - There is a buffer of size n. Consumers take items from buffer, one item at a time (By this I mean, whenever a consumer thread has access to buffer, it won't take more than…
Sashank
  • 590
  • 7
  • 22
2
votes
0 answers

Node.js - How to ensure mutual exclusion

In Node.js I have code similar to the following: function requestHandler() { expression1; // Not I/O related expression2; } The question I have is if it is possible that expression1 gets executed for request 1 and then expression1 for…
Robert Hickman
  • 997
  • 1
  • 11
  • 22
2
votes
2 answers

ReleaseMutex fails in single-thread c# windows forms app

I've looked through SO for this issue, but the other instances seem to relate only to multi-threaded app issues. My app is a straightforward single-form, single-thread app and I'm just using a mutex to ensure only one instance is run on the host…
TonyLongson
  • 121
  • 1
  • 5
2
votes
0 answers

Concerning PTHREAD_MUTEX_ROBUST

According to the official doc (emphasis mine): PTHREAD_MUTEX_ROBUST If the process containing the owning thread of a robust mutex terminates while holding the mutex lock, the next thread that acquires the mutex shall be notified about the…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
2
votes
5 answers

Thread-Safe implementation of an object that deletes itself

I have an object that is called from two different threads and after it was called by both it destroys itself by "delete this". How do I implement this thread-safe? Thread-safe means that the object never destroys itself exactly one time (it must…
IanH
  • 3,968
  • 2
  • 23
  • 26
2
votes
2 answers

Race Condition - Can Mutexes Be More Flexible?

I have a TThread object named TTestThread. When the threads are created, they make a local copy of the global configuration variables. The user is allowed to change the global configuration variables at any time, and when he does so, all threads are…
Pascal Bergeron
  • 761
  • 3
  • 12
  • 27
2
votes
3 answers

Does my solution satisfy mutual exclusion requirements?

I found a solution to the mutual-exclusion problem online that has two processes P0 and P1. (Assume that the variable turn is initialized to 0) volatile int turn; Process P0: /* Other code */ while (turn != 0) { } /* Do nothing and wait. */ …
Tia
  • 27
  • 3
2
votes
0 answers

Deadlock when reading from a stream in FUSE

My understanding of FUSE's multithreaded read cycle is something like this: .... .-> read --. / \ open ---> read ----+-> release \ / `-> read --' .... i.e., Once…
Xophmeister
  • 8,884
  • 4
  • 44
  • 87
2
votes
3 answers

How to use std::lock_guard on a class member mutex

In the following code the bad method fails to compile, but the good method does not. Why is providing the explicit reference to this making a difference here? #include class Foo { private: std::mutex lock_; public: Foo() = default; …
maxywb
  • 2,275
  • 1
  • 19
  • 25
2
votes
2 answers

Mutex not releasing

My c# WinForm solution contains several projects including an Admin project containing frmAdmin and a User project containing frmUser. A third project contains frmTimer that has a timer that periodically launches frmUser. I want frmTimer to not…
Frederick
  • 213
  • 1
  • 5
  • 14
1 2 3
99
100