Operating Systems, 2011, Danny Hendler & Amnon Meisels 1 Distributed Mutual Exclusion  Introduction  Ricart and Agrawala's algorithm  Raymond's algorithm.

Slides:



Advertisements
Similar presentations
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Distributed Mutual Exclusion.
Advertisements

CS542 Topics in Distributed Systems Diganta Goswami.
Ricart and Agrawala’s Algorithm
Token-Dased DMX Algorithms n LeLann’s token ring n Suzuki-Kasami’s broadcast n Raymond’s tree.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
1 Algorithms and protocols for distributed systems We have defined process groups as having peer or hierarchical structure and have seen that a coordinator.
Operating Systems, 2011, Danny Hendler & Amnon Meisels 1 Distributed Synchronization: outline  Introduction  Causality and time o Lamport timestamps.
Page 1 Mutual Exclusion* Distributed Systems *referred to slides by Prof. Paul Krzyzanowski at Rutgers University and Prof. Mary Ellen Weisskopf at University.
Operating Systems, 112 Practical Session 14, Distributed synchronization.
CS 582 / CMPE 481 Distributed Systems
Shared Memory Coordination We will be looking at process coordination using shared memory and busy waiting. –So we don't send messages but read and write.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Distributed Snapshots –Termination detection Election algorithms –Bully –Ring.
EEC-681/781 Distributed Computing Systems Lecture 11 Wenbing Zhao Cleveland State University.
CS 425 / ECE 428 Distributed Systems Fall 2014 Indranil Gupta (Indy) Lecture 12: Mutual Exclusion All slides © IG.
Distributed Mutual Exclusion Béat Hirsbrunner References G. Coulouris, J. Dollimore and T. Kindberg "Distributed Systems: Concepts and Design", Ed. 4,
1 Distributed Process Management: Distributed Global States and Distributed Mutual Exclusion.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
Dr. Kalpakis CMSC 621, Advanced Operating Systems. Fall 2003 URL: Distributed Mutual Exclusion.
Distributed Mutual Exclusion
1 A Mutual Exclusion Algorithm for Ad Hoc Mobile networks Presentation by Sanjeev Verma For COEN th Nov, 2003 J. E. Walter, J. L. Welch and N. Vaidya.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
4.5 DISTRIBUTED MUTUAL EXCLUSION MOSES RENTAPALLI.
4.5 Distributed Mutual Exclusion Ranjitha Shivarudraiah.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Mutual Exclusion Steve Ko Computer Sciences and Engineering University at Buffalo.
CSC Distributed Mutual Exclusion Presenter: Weiling Li Instructor: Dr. Zhang.
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms –Bully algorithm.
Chapter 2/6 –Critical Section Problem / Mutual exclusion progress, bounded wait –Hardware Solution disable interrupts –problems ? –Software Solution busy.
CS425 /CSE424/ECE428 – Distributed Systems – Fall 2011 Material derived from slides by I. Gupta, M. Harandi, J. Hou, S. Mitra, K. Nahrstedt, N. Vaidya.
Coordination and Agreement. Topics Distributed Mutual Exclusion Leader Election.
Presenter: Long Ma Advisor: Dr. Zhang 4.5 DISTRIBUTED MUTUAL EXCLUSION.
1 Chapter 10 Distributed Algorithms. 2 Chapter Content This and the next two chapters present algorithms designed for loosely-connected distributed systems.
Ch10 Synchronization and Election. Introduction We shall be concerned with basic distributed algorithms for Synchronization (basic idea ordering) Required.
Vector Clock Each process maintains an array of clocks –vc.j.k denotes the knowledge that j has about the clock of k –vc.j.j, thus, denotes the clock of.
Studying Different Problems from Distributed Computing Several of these problems are motivated by trying to use solutiions used in `centralized computing’
Lecture 10 – Mutual Exclusion Distributed Systems.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Mutual Exclusion & Leader Election Steve Ko Computer Sciences and Engineering University.
Distributed Transaction Management, Fall 2002Lecture 2 / Distributed Locking Jyrki Nummenmaa
ITEC452 Distributed Computing Lecture 6 Mutual Exclusion Hwajung Lee.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are:  Resource sharing  Avoiding concurrent update on shared data  Controlling the.
Hwajung Lee. Mutual Exclusion CS p0 p1 p2 p3 Some applications are: 1. Resource sharing 2. Avoiding concurrent update on shared data 3. Controlling the.
A Tree Based Algorithm fro Distributed Mutual Exclusion Addy Gronquist 11/19/2003.
Page 1 Mutual Exclusion & Election Algorithms Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content.
Lecture 12-1 Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2012 Indranil Gupta (Indy) October 4, 2012 Lecture 12 Mutual Exclusion.
Lecture 7- 1 CS 425/ECE 428/CSE424 Distributed Systems (Fall 2009) Lecture 7 Distributed Mutual Exclusion Section 12.2 Klara Nahrstedt.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 15: Coordination.
1 Chapter 11 Global Properties (Distributed Termination)
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
CSC 8420 Advanced Operating Systems Georgia State University Yi Pan Transactions are communications with ACID property: Atomicity: all or nothing Consistency:
Revisiting Logical Clocks: Mutual Exclusion Problem statement: Given a set of n processes, and a shared resource, it is required that: –Mutual exclusion.
CS 425 / ECE 428 Distributed Systems Fall 2015 Indranil Gupta (Indy) Oct 1, 2015 Lecture 12: Mutual Exclusion All slides © IG.
Lecture 18: Mutual Exclusion
4.5 Distributed Mutual Exclusion
Mutual Exclusion Continued
Distributed Mutual Exclusion
Practical Session 13 Distributed synchronization
A Mutual Exclusion Algorithm for Ad Hoc Mobile Networks
Distributed Mutual Exclusion
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Outline Distributed Mutual Exclusion Introduction Performance measures
Mutual Exclusion CS p0 CS p1 p2 CS CS p3.
CSE 486/586 Distributed Systems Mutual Exclusion
Synchronization (2) – Mutual Exclusion
ITEC452 Distributed Computing Lecture 7 Mutual Exclusion
Prof. Leonardo Mostarda University of Camerino
Distributed Mutual Exclusion
Distributed Systems and Concurrency: Synchronization in Distributed Systems Majeed Kassis.
Distributed Mutual eXclusion
CSE 486/586 Distributed Systems Mutual Exclusion
Presentation transcript:

Operating Systems, 2011, Danny Hendler & Amnon Meisels 1 Distributed Mutual Exclusion  Introduction  Ricart and Agrawala's algorithm  Raymond's algorithm This presentation is based on the book: “Distributed operating-systems & algorithms” by Randy Chow and Theodore Johnson

2 Operating Systems, 2011, Danny Hendler & Amnon Meisels  Distributed mutual exclusion required (e.g.) for transaction processing on replicated data  We assume there are no failures o Processors do not fail o Communication links do not fail  It is easy to implement mutual exclusion using totally-ordered timestamps o The first algorithm we show may use Lamport's timestamps Distributed mutual exclusion: introduction

3 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: high-level ideas  When you want to enter your CS o Record your timestamp o Ask everyone else whether they “permit”  When asked for a permission o Halt response if in CS o Halt response if in entry code with a smaller timestamp (we need total order between timestamps) o Otherwise, “permit”  Upon exit from CS o Send halted responses (if any)

4 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: data-structures Per processor variables timestamp current_time Timestamp my_timestamp integer reply_count boolean isRequesting boolean reply_deferred[M] Processor’s current Lamport timestamp

5 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: data-structures Per processor variables timestamp current_time Timestamp my_timestamp integer reply_count boolean isRequesting boolean reply_deferred[M] The timestamp of the processor’s current request

6 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: data-structures Per processor variables timestamp current_time Timestamp my_timestamp integer reply_count boolean isRequesting boolean reply_deferred[M] The number of permissions that the processor still need to collect before entering the CS

7 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: data-structures Per processor variables timestamp current_time Timestamp my_timestamp integer reply_count boolean isRequesting boolean reply_deferred[M] True iff this processor is requesting or using the CS

8 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: data-structures Per processor variables timestamp current_time Timestamp my_timestamp integer reply_count boolean isRequesting boolean reply_deferred[M] Entry j is true iff this processor deferred replying to processor j’s request

9 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: entry-code Request_CS: 1my_timstamp  current_time 2isRequesting  TRUE 3Reply_count  M-1 4for every other processor j 5 send(REMOTE_REQUEST; my_timestamp) 6wait until reply_count = 0 Set the (Lamport) timestamp of my request

10 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: entry-code Request_CS: 1my_timstamp  current_time 2isRequesting  TRUE 3Reply_count  M-1 4for every other processor j 5 send(REMOTE_REQUEST; my_timestamp) 6wait until reply_count = 0 Mark that this processor is requesting entry to CS

11 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: entry-code Request_CS: 1my_timstamp  current_time 2isRequesting  TRUE 3Reply_count  M-1 4for every other processor j 5 send(REMOTE_REQUEST; my_timestamp) 6wait until reply_count = 0 Need to receive replies from all other processors

12 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: entry-code Request_CS: 1my_timstamp  current_time 2isRequesting  TRUE 3Reply_count  M-1 4for every other processor j 5 send(REMOTE_REQUEST; my_timestamp) 6wait until reply_count = 0 Request permission from all other processors

13 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: entry code Request_CS: 1my_timstamp  current_time 2isRequesting  TRUE 3Reply_count  M-1 4for every other processor j 5 send(REMOTE_REQUEST; my_timestamp) 6wait until reply_count = 0 When all other processors reply – may enter the CS

14 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: monitoring CS_monitoring: Wait until a REMOTE_REUQUEST or REPLY message is received REMOTE_REQUEST(sender; request_time) 1.Let j be the sender of the REMOTE_REQUEST message 2.if (not is_requesting or my_timestamp > request_time) 3. send(j, REPLY) 4.else 5. reply_deferred[j]=TRUE REPLY 4.reply_count  reply_count-1 Listener thread to respond to protocol messages at all times

15 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: monitoring Upon receipt of remote request CS_monitoring: Wait until a REMOTE_REUQUEST or REPLY message is received REMOTE_REQUEST(sender; request_time) 1.Let j be the sender of the REMOTE_REQUEST message 2.if (not is_requesting or my_timestamp > request_time) 3. send(j, REPLY) 4.else 5. reply_deferred[j]=TRUE REPLY 4.reply_count  reply_count-1

16 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: monitoring If should grant processor j’th request CS_monitoring: Wait until a REMOTE_REUQUEST or REPLY message is received REMOTE_REQUEST(sender; request_time) 1.Let j be the sender of the REMOTE_REQUEST message 2.if (not is_requesting or my_timestamp > request_time) 3. send(j, REPLY) 4.else 5. reply_deferred[j]=TRUE REPLY 4.reply_count  reply_count-1

17 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: monitoring Send reply to processor j CS_monitoring: Wait until a REMOTE_REUQUEST or REPLY message is received REMOTE_REQUEST(sender; request_time) 1.Let j be the sender of the REMOTE_REQUEST message 2.if (not is_requesting or my_timestamp > request_time) 3. send(j, REPLY) 4.else 5. reply_deferred[j]=TRUE REPLY 4.reply_count  reply_count-1

18 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: monitoring Otherwise, defer replying to this request CS_monitoring: Wait until a REMOTE_REUQUEST or REPLY message is received REMOTE_REQUEST(sender; request_time) 1.Let j be the sender of the REMOTE_REQUEST message 2.if (not is_requesting or my_timestamp > request_time) 3. send(j, REPLY) 4.else 5. reply_deferred[j]=TRUE REPLY 4.reply_count  reply_count-1

19 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: monitoring Upon receiving a reply, decrement reply_count CS_monitoring: Wait until a REMOTE_REUQUEST or REPLY message is received REMOTE_REQUEST(sender; request_time) 1.Let j be the sender of the REMOTE_REQUEST message 2.if (not is_requesting or my_timestamp > request_time) 3. send(j, REPLY) 4.else 5. reply_deferred[j]=TRUE REPLY 4.reply_count  reply_count-1

20 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: exit section Release_CS_monitoring: 1.is_requesting  false 2.For j=1 through M (other than this processor's ID) 3. if reply_deferred[i]=TRUE 4. send(j, REPLY) 5. reply_deferred[j]=FALSE No longer requesting CS

21 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: exit section Release_CS_monitoring: 1.is_requesting  false 2.For j=1 through M (other than this processor's ID) 3. if reply_deferred[i]=TRUE 4. send(j, REPLY) 5. reply_deferred[j]=FALSE For each processor awaiting a reply from this processor, send reply and mark that there are no more deferred replies.

22 Operating Systems, 2011, Danny Hendler & Amnon Meisels Ricart and Agrawal's algorithm: comments What is the number of messages required for each passage through the critical section? 2(M-1) messages. Let's see a more message-efficient algorithm…

23 Operating Systems, 2011, Danny Hendler & Amnon Meisels Distributed Mutual Exclusion  Introduction  Ricart and Agrawala's algorithm  Raymond's algorithm

24 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: high-level ideas  There is a single token in the system o Only the holder of the token may enter the CS  Processors communicate by using a static tree structure o Requests for the token are sent o The token itself is sent when available and requested  Processors maintain FIFO request queues to prevent starvation  If processors request entry “one at a time” – at most a logarithmic number of messages per entry o When there are many simultaneous requests, the number of messages per entry typically decreases

25 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: high-level ideas (cont'd)  Algorithm invariant: tree is always oriented towards token holder Token holder

26 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: data-structures Per processor variables Boolean token_holder Boolean inCS current_dir requests_queue True iff this processor currently holds the token

27 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: data-structures Per processor variables Boolean token_holder Boolean inCS current_dir requests_queue True iff this processor is currently in the critical section

28 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: data-structures Per processor variables Boolean token_holder Boolean inCS current_dir requests_queue The neighbor that is in the direction of the token (or self if this processor holds the token)

29 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: data-structures Per processor variables Boolean token_holder Boolean inCS current_dir requests_queue FIFO queue holding IDs of neighbors from which requests for the token arrived (may also contain self)

30 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) If this processor currently holds the token it immediately enters CS. Otherwise…

31 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) If requests queue is empty, send a request for the token. (If queue is non-empty, a request for the token was already sent.)

32 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) Enqueue ‘self’ to requests queue since this request is on behalf of this processor

33 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) When token_holder is set, this processor has the token and may enter the CS

34 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) No longer in critical section

35 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) If requests are waiting…

36 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) Dequeue the next hop for the earliest request and send the TOKEN to it. Also, update orientation of the token.

37 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) This processor no longer holds token

38 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: entry and exit code Request_CS: 1If not token_holder 2 if requests_queue.isEmpty( ) 3 send(current_dir, REQUEST) 4 requests_queue.enqueue(self) 5 wait until token_holder is true 6inCS  true Release_CS: 7.inCS  false 8.If not requests_queue.isEmpty( ) 9. current_dir  requests_queue.dequeue( ) 10. send(current_dir, TOKEN) 11. token_holder  false 12. if not requests_queue.isEmpty( ) 13. send(current_dir, REQUEST) If there are more requests in this processor’s queue, send another request for the token

39 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Listener thread to respond to protocol messages at all times

40 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Upon a request. If current processor holds token…

41 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) If current processor in CS then request must wait, enqueue the direction of requesting processor

42 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Otherwise current processor holds the token but is not in CS, hence requests queue is empty. Send token to where the request came from, mark that current processor no longer holds token, and the new orientation of the otken…

43 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Otherwise current processor does not hold the token…

44 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) If requests queue is empty, send request in the direction of the token…

45 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Enqueue the direction of this request…

46 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Upon the arrival of the token…

47 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Dequeue oldest request and set new orientation of the token to its direction

48 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) If request was by this processor, mark that it currently has the token and may enter the CS

49 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) Otherwise, send the token in the direction of the request

50 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: monitoring Monitor_CS: 1while (true) 2 wait for a REQUEST or a TOKEN message REQUEST 3. if token_holder 4. if inCS 5. requests_queue.enqueue(sender) 6. else 7. current_dir  sender 8. send(current_dir, TOKEN) 9. token_holder  false 10. else 11. if requests_queue.isEmpty() 12. send(current_dir,REQUEST) 13. requests_queue.enqueue(sender) TOKEN 14. current_dir  requests_queue.dequeue( ) 15. if current_dir = self 16. token_holder  true 17. else 18. send(current_dir, TOKEN) 19. if not requests_queue.isEmpty( ) 20. send(current_dir, REQUEST) If the queue is non-empty, send another request for the token

51 Operating Systems, 2011, Danny Hendler & Amnon Meisels Raymond's algorithm: execution scenario