Skip to main content

Questions tagged [mutex]

1 vote
2 answers
1k views

design pattern to avoid deadlock with mutex in golang

What would the appropriate design pattern to avoid deadlock when several functions use the same mutex ? It is quite easy to forget what method uses the lock and so it happens that you call a function ...
cylon86's user avatar
  • 111
0 votes
1 answer
158 views

Difference between outcome of using mutex/spinlock/semaphore in this deadlock situation?

I'm not sure if my answers to the following exercise is correct: Suppose the program is run with two threads. Further suppose that the following sequence of events occurs: Time Thread 0 ...
Lilian Shi's user avatar
3 votes
3 answers
5k views

When should one utilize Atomic Operations?

I have never used atomic operations, and remain largely ignorant of how to utilize them. And yet, I often come across objects like this when peering into Qt's backend: https://doc.qt.io/qt-6/...
Anon's user avatar
  • 3,649
6 votes
1 answer
1k views

Specify that a method needs a mutex held when calling

Current situation Right now I have a method like Data lookupData(Key id) { std::lock_guard<std::mutex> lock(m_mutex); auto it = m_dict.find(id); if(it == m_dict.end()) { ...
Daniel McLaury's user avatar
2 votes
1 answer
565 views

Make multiple data structures thread safe without multiple mutexes

In my application, I have a class which I call a "Signal" (Think Qt signals if you are familiar with that) that represents a one-to-many connection. Objects can register handlers to the ...
Patrick Wright's user avatar
0 votes
1 answer
1k views

Is a mutex lock always implemented as spin waiting?

Is a mutex lock always implemented as spin waiting? Can a mutex lock be implemented as block waiting? (Operating System Concepts section 5.4 only mentions the implementation by spin waiting. See below....
Tim's user avatar
  • 5,555
1 vote
2 answers
2k views

Why is it that "the process that locks the mutex must be the one to unlock it "?

Here are some discussions about mutex (lock) and binary semaphore from two OS books. Stalling's Operating Systems book says A concept related to the binary semaphore is the mutex . A key ...
Tim's user avatar
  • 5,555
-1 votes
1 answer
204 views

is there difference between releasing two semaphores in the same or reverse order as they are acquired?

Generally, if two semaphores are acquired one after the other, is there difference between releasing them in the same order or the reverse order as they are acquired? In the following solution to the ...
Tim's user avatar
  • 5,555
28 votes
5 answers
7k views

Is "releases mutexes in reverse order" required to make this deadlock-prevention method work?

Operating System Concepts says 7.4.4 Circular Wait The fourth and final condition for deadlocks is the circular-wait condition. One way to ensure that this condition never holds is to impose a total ...
Tim's user avatar
  • 5,555
-2 votes
2 answers
1k views

what would happen if you signal() before wait()?

A bakery shop has to provide a stream of muffins for customers. The muffins are made by a baker in the kitchen and placed on a conveyor belt. The conveyor belt carries the muffins to where the ...
Callum Bell's user avatar
8 votes
5 answers
9k views

Implementing a hash table with true concurrency

This was recently a question I was asked in a screening and it got me thinking. I never totally settled on how the conversation ended, and I did some digging. None of the answers I saw seemed ...
kiss-o-matic's user avatar
0 votes
0 answers
86 views

Pausing threads calling the same method by making them try to lock an already locked mutex

I am confronted to a question regarding synchronisation between threads having shared data. This is a stripped down versino of my class : class Foo { private: boost::mutex m_mutex; std:vector&...
drbradock's user avatar
0 votes
1 answer
116 views

Multithreading - 2 active running threads calling each other without blocking itself

I have an implemented UDP receiver which is continuously receiving DTN packets (UDP encapsulated) and performing some operations on them. This whole process is working on a single main thread. However ...
Caspian's user avatar
  • 13
2 votes
0 answers
199 views

Testing an algorithm for safety in mutual exclusion

I am attempting to write a code to test Lamport's Mutual Exclusion algorithm for safety as a correctness measure. I am running the alogrithm on a single core cpu machine with multiple processes ...
Varun Hegde's user avatar
3 votes
0 answers
64 views

Release Phase in Lamport's Mutual Exclusion Algorithm

I was studying Lamport's mutual exclusion algorithm from the original paper, and noticed a difference in the release phase to the one given in Wikipedia. In the original paper, author states that : ...
Varun Hegde's user avatar

15 30 50 per page