Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i.

Similar presentations


Presentation on theme: "1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i."— Presentation transcript:

1 1 Chapter 5 Concurrency

2 2 Concurrency

3 3

4 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i = 1; return true; } else { return false; }

5 5 Mutual Exclusion: Hardware Support Exchange Instruction void exchange(int *register, int *memory) { int temp; temp = *memory; *memory = *register; *register = temp; }

6 6 Mutual Exclusion

7 7 Semaphore Primitives

8 8 Binary Semaphore Primitives

9 9 Mutual Exclusion Using Semaphores

10 10

11 11

12 12 Producer/Consumer Problem

13 13 Producer producer: while (true) { /* produce item v */ b[in] = v; in++; }

14 14 Consumer consumer: while (true) { while (in <= out) /*do nothing */; w = b[out]; out++; /* consume item w */ }

15 15

16 16

17 17 Producer with Circular Buffer producer: while (true) { /* produce item v */ while ((in + 1) % n == out) /* do nothing */; b[in] = v; in = (in + 1) % n }

18 18

19 19 Readers/Writers Problem Any number of readers may simultaneously read the file Only one writer at a time may write to the file If a writer is writing to the file, no reader may read it

20 20

21 21


Download ppt "1 Chapter 5 Concurrency. 2 Concurrency 3 4 Mutual Exclusion: Hardware Support Test and Set Instruction boolean testset (int *i) { if (*i == 0) { *i."

Similar presentations


Ads by Google