Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
c code for lamport algo for mutual exclusion
#1

Lamport's Mutual Exclusion Algorithm

Assumes messages are delivered in FIFO order between each pair of sites
Is not based on tokens
Is based on Lamport's clock synchronization scheme*
Each request gets a timestamp
Requests with lower timestamps take priority over requests with higher timestamps
Each site maintains a queue of pairs (timestamp, site), ordered by timestamp
* Are these the single-integer valued clocks, or the vector clocks?

The Algorithm

Request
Si sends REQUEST(tsi, i) to all sites in its request set Ri and puts the request on request_queuei
when Sj receives REQUEST(tsi, i) from Si it returns a timestamped REPLY to Si and places Si's request on request_queuej
Si waits to start the CS until both
[L1:] Si has received a message with timestamp > (tsi, i) from all other sites
[L2:] Si's request is at the top of request_queuei
Release
Si removes request from top of request_queuei and sends time-stamped RELEASE message to all the sites in its request set
when Sj receives a RELEASE messages from Si it removes Si's request from request_queuej
Correctness

Suppose Si and Sj are executing the CS concurrently.

L1 and L2 must hold at both sites concurrently.

Si and Sj both have requests at top of their queues and L1 holds, at some instant t.

WLOG suppose Si's request has earlier timestamp than Sj's.
(Remember the tie-breaking rule!)

Assuming communication channels are FIFO, at instant t Si's request is queued at Sj, when Sj is in the CS and Sj's own request is at the top of the queue, ahead of a smaller timestamp request.

This is a contradiction.
Reply

#2
c code for lamport algo for mutual exclusion

Lamport's bakery algorithm is a computer algorithm devised by computer scientist Leslie Lamport, which is intended to improve the safety in the usage of shared resources among multiple threads by means of mutual exclusion.

In computer science, it is common for multiple threads to simultaneously access the same resources. Data corruption can occur if two or more threads try to write into the same memory location, or if one thread reads a memory location before another has finished writing into it. Lamport's bakery algorithm is one of many mutual exclusion algorithms designed to prevent concurrent threads entering critical sections of code concurrently to eliminate the risk of data corruption.
Reply

#3

To get full information or details of c code for lamport algo for mutual exclusion please have a look on the pages

https://cs.unc.edu/ anderson/papers/lamport.pdf

http://dl.acmcitation.cfm?id=176479

if you again feel trouble on c code for lamport algo for mutual exclusion please reply in that page and ask specific fields in c code for lamport algo for mutual exclusion
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Powered By MyBB, © 2002-2024 iAndrew & Melroy van den Berg.