Avoid Deadlock with Semaphores

Image for post
Image for post
Photo by Drew Hays on Unsplash

The importance

Image for post
Image for post
Photo by Maksym Kaharlytskyi on Unsplash
Image for post
Image for post
Photo by Sarah Kilian on Unsplash

The practical example

Image for post
Image for post
Click for Gist
Image for post
Image for post
Click for Gist
Image for post
Image for post
Image for post
Image for post
A sample output

The naive solution

Image for post
Image for post
Click for Gist
Image for post
Image for post
The problem

The solution: A semaphore

The theoretical semaphore

Image for post
Image for post
performwork
Image for post
Image for post

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