Questions tagged [mutual-exclusion]

Questions about the concurrency-control requirement of ensuring that no two processes are simultaneously in a critical section (a period when the process is accessing a shared resource). Failing to achieve mutual exclusion leads to the problem of data races.

59 questions
54
votes
3 answers

Contrasting Peterson’s and Dekker’s algorithms

I am trying to understand the algorithms by Peterson and Dekker which are very similar and display a lot of symmetries. I tried to formulate the algorithms in informal language like follows: Peterson's: "I want to enter." …
gbag
  • 719
  • 1
  • 6
  • 9
19
votes
1 answer

Are there hardware lock implementations without test-and-set or swap?

Locks are usually implemented thru test-and-set and swap machine-level instructions. Are there other implementations that do not use these? Also, can we say that all hardware level solutions to the critical section problem can be categorized into…
11
votes
3 answers

Why would you use a monitor instead of a semaphore?

I am currently attending the concurrent programming course in my university and we recently started talking about the concept of a monitor. While I understand the necessity of mutual exclusion, I do not understand why I would use a monitor for that.…
Dennis Hein
  • 316
  • 2
  • 11
9
votes
2 answers

Does Peterson's 2-process mutual exclusion algorithm account for dying processes?

I think that in Peterson's algorithm for mutual exclusion, if the process first to enter the critical section were to die or be cancelled, the other process would loop forever, waiting to enter the critical section. In the picture, if process 1 is…
8
votes
1 answer

What is the practical relevance of textbook mutual exclusion algorithms?

There's been a fair amount of research on mutual exclusion algorithms - e.g. a lot of it is presented in classic textbooks such as The Art of Multiprocessor Programming, where an entire chapter is devoted to them. I'm wondering what are the…
jkff
  • 2,269
  • 1
  • 14
  • 17
7
votes
3 answers

Mutual exclusion for n processes

I want to implement mutual exclusion for $n$ processes. Critical section code: int turn = 0; /* shared control variable */ Pi: /* i is 0 or 1 */ while (turn != i) ; /* busy wait */ CSi; turn = 1 - i; This…
Bassam Badr
  • 173
  • 3
7
votes
1 answer

Lamport’s fast mutual exclusion algorithm intuition

Here's Lamport’s fast mutual exclusion algorithm: want[i]:=true fast-lock:=i if slow-lock<>0 then want[i]:=false while (slow-lock<>0) {//busy wait} goto 1 slow-lock:=i if fast-lock <> i then want[i]:=false for j:=1 to n do: …
Alex Goft
  • 235
  • 2
  • 7
7
votes
3 answers

Solutions to synchronization problem need to be executed in critical section

I was reading about synchronization problems for cooperating processes and i learned that only hardware solutions like test_and_wait() and compare_and_set() are performed atomically at the hardware level and in all other software solutions like…
6
votes
1 answer

Why $e(C_i) = D_i$ is correct assumption? (FLP Impossibility 1985 - Lemma 3)

Please bear with my unhelpful typesetting. My question is regarding well known FLP paper Impossibility of Distributed Consensus with One Faulty Process by Fischer, Lynch and Patterson While discussing Lemma 3, in 4th paragraph, authors make an…
6
votes
1 answer

Software mutexes and consensus number 1

There are numerous possibilities to implement a software mutex using only shared memory (e.g. Dekker's algorithm). Recently I've read the following from a paper "Wait-free Synchronization" by M. Herlihy: there exists no two-process consensus…
artemonster
  • 379
  • 2
  • 9
6
votes
1 answer

Mutex implementation on top of a minimalistic preemptive scheduler

In this question, I'm implementing some synchronization primitives in the standard library of an operating system. Specifically, I want to implement mutexes and condition variables. This is on top of a microkernel with a preemptive scheduler (a…
5
votes
1 answer

Mutual exclusion algorithm using only atomic reads and writes for unknown number of processes and robust to process abortion

I am trying to come up with a mutual exclusion algorithm that is based only on atomic reads and atomic writes of shared memory (i.e. no compare-and-swap or similar). Apart from mutual exclusion and deadlock freedom, it needs to fulfill the following…
Markus A.
  • 223
  • 1
  • 6
5
votes
1 answer

What is a counterexample for Lamport's distributed mutual exclusion algorithm with non-FIFO message queues?

Lamport's distributed mutual exclusion algorithm (also described here) solves mutual exclusion problem for $N$ processes with $3(N-1)$ messages per request ("take and release lock" cycle). It requires that for each pair of processes $P$ and $Q$ all…
4
votes
0 answers

Classic Problems on Process Synchronization

I have been studying Process Synchronization and inter-process communication in Operating Systems Engineering and have come across multiple problems like "Sleeping Barbers", "Producer Consumers", "Dining Philosophers" and "Reader Writers" . While…
theraven
  • 41
  • 2
4
votes
2 answers

Does mutual exclusion hold in this case?

I entered into a discussion with a friend on the following question, which asks if mutual exclusion holds: Consider two processes: $s_1$ and $s_2$ are two variables, set equal initially. P1: while $s_1 = s_2$: wait. /execute critical…
1
2 3 4