Avoid Deadlock with Semaphores

Photo by Drew Hays on Unsplash

The importance

Photo by Maksym Kaharlytskyi on Unsplash
Photo by Sarah Kilian on Unsplash

The practical example

Click for Gist
Click for Gist
A sample output

The naive solution

Click for Gist
The problem

The solution: A semaphore

The theoretical semaphore

performwork

Conclusion

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store