No commit activity in last 3 years
No release in over 3 years
Algorithm devised by Boleslaw Szymanski. This MutEx has linear wait and only 5 communication variables
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.8.0, ~> 3.8
>= 3.8.0, ~> 3.8
 Project Readme

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.