Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ebyrds/szymanskis_mutex
Algorithm devised by Boleslaw Szymanski. This MutEx has linear wait and only 5 communication variables
https://github.com/ebyrds/szymanskis_mutex
mutex mutex-lock mutex-synchronisation mutexes race-conditions ruby rubygem szymanski
Last synced: 2 months ago
JSON representation
Algorithm devised by Boleslaw Szymanski. This MutEx has linear wait and only 5 communication variables
- Host: GitHub
- URL: https://github.com/ebyrds/szymanskis_mutex
- Owner: EByrdS
- License: mit
- Created: 2018-10-11T15:09:37.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-12T18:10:36.000Z (about 6 years ago)
- Last Synced: 2024-04-25T19:44:26.416Z (8 months ago)
- Topics: mutex, mutex-lock, mutex-synchronisation, mutexes, race-conditions, ruby, rubygem, szymanski
- Language: Ruby
- Size: 32.2 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/EByrdS/szymanskis_mutex.png?branch=master)](https://travis-ci.org/EByrdS/szymanskis_mutex)
[![Inline docs](http://inch-ci.org/github/EByrdS/szymanskis_mutex.svg?branch=master)](http://inch-ci.org/github/EByrdS/szymanskis_mutex)
![](https://ruby-gem-downloads-badge.herokuapp.com/szymanskis_mutex?extension=png)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
[![Gem](https://img.shields.io/gem/v/szymanskis_mutex.svg?style=flat)](http://rubygems.org/gems/szymanskis_mutex "View this project in Rubygems")
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues)# 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.)```ruby
class RaceConditionReproducer
@@value = 0def mutex_increment
SzymanskisMutex.mutual_exclusion(:add) { unsafe_increment }
enddef unsafe_increment
sleep 2
temp = @@valuesleep 2
temp += 1sleep 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.