Algorithm devised by Boleslaw Szymanski. This MutEx has linear wait and only 5 communication variables
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
LICENSE
README.md
szymanskis_mutex.gemspec

README.md

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.