Skip to main content

Questions tagged [mutex]

Filter by
Sorted by
Tagged with
1 vote
2 answers
1k views

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
162 views

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

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

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
577 views

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? 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,565
1 vote
2 answers
2k views

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,565
-1 votes
1 answer
205 views

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,565
28 votes
5 answers
7k views

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,565
-2 votes
2 answers
1k views

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

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
87 views

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

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

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

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
4 votes
1 answer
1k views

Let’s assume there is a function EventHandler that is called on multiple threads at different points in time. EventHandler has to call SomeOtherFunction, but these calls shall only happen on one ...
Martin's user avatar
  • 476
15 votes
2 answers
2k views

As the title says: How do you properly test and benchmark different implementations of mutexes in c++? Essentially I wrote my own std::mutex like class for a project running on a 2 core, armv7 with ...
MikeMB's user avatar
  • 264
1 vote
1 answer
2k views

The relatively large size of std::mutex on different platforms (e.g. 40 or even 80 bytes) is often explained as ensuring the mutexes don't occupy the same cache-lines and so don't incur logically ...
Persixty's user avatar
  • 383
8 votes
2 answers
5k views

Recently I had to implement a Semaphore using a Mutex and a Conditional Variable (this combination is also known as a Monitor) for an exercise at the university: the Semaphore's decrement operation ...
Qqwy's user avatar
  • 4,947