Semaphores are available in nearly every popular programming language.
In parallel/concurrent programming, barriers hold significant importance.
In this repository, different approaches to barrier implementations of semaphores will be demonstrated. Alongside with the implementation itself, the corresponding errors are explained in detail.
For each code, there is a next version, trying to solve the previous error. Order of the trials are as follows:
- version1.py (most straight-forward barrier implementation trial)
- version2.py (solving the deadlock in version1)
- version2-problem.py (version2 works, but not in loops)
- reusable-1.py (trying create loop-friendly barriers)
- reusable-2.py (fixing the interrupt related problem in all previous versions)
- solution (fixes the issue of one thread may advance in iterations without waiting for others)
All errors are explained in detail as comments in the python files.
The algorithms for above implementations are taken from the book:
The Little Book of Semaphores Allen B. Downey Version 2.2.1 [https://www.cse.iitb.ac.in/~mythili/os/references/LittleBookOfSemaphores.pdf]\