Skip to content

Algorithm devised by Boleslaw Szymanski. This MutEx has linear wait and only 5 communication variables

License

Notifications You must be signed in to change notification settings

EByrdS/szymanskis_mutex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Inline docs MIT license Gem contributions welcome

Szymański's Mutual Exclusion Algorithm

This algorithm is modeled on a waiting room with an entry and exit doorway. Initially the entry door is open and the exit door is closed. All processes which request entry into the critical section at the same time enter the waiting room; the last of them closes the entry door and opens the exit door. The processes then enter the critical section one by one. The last process to leave the critical section closes the exit door and reopens the entry door so he next batch of processes may enter.

Getting Started

Install the gem or add it to the Gemfile.

$ gem install szymanskis_mutex

Provide a block containing the critical section to the class method mutual_exclusion(concern). The parameter concern is used so that you can have different use cases without them accessing the same variables. (You can have as many separate MutEx as you want.)

class RaceConditionReproducer
 @@value = 0

 def mutex_increment
   SzymanskisMutex.mutual_exclusion(:add) { unsafe_increment }
 end

 def unsafe_increment
   sleep 2
   temp = @@value

   sleep 2
   temp += 1

   sleep 2
   @@value = temp
 end
end

The MutEx will work across different instances of the same class as it works with class variables.

Contribution

Pull Requests will be reviewed before merging. Issues are being addressed. All Pull Requests must contain specs for the changes.

About

Algorithm devised by Boleslaw Szymanski. This MutEx has linear wait and only 5 communication variables

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages