LittleBookOfSemaphores | Go Language take on Allen Downey | Learning library
kandi X-RAY | LittleBookOfSemaphores Summary
kandi X-RAY | LittleBookOfSemaphores Summary
A Go Language take on Allen Downey's Free Book "The Little Book of Semaphores"
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- santa runs the santa
- smoker
- enron to bond
- serf waits for the queue to exit .
- hacker
- barber starts a background goroutine .
- customerFunc runs a customer function .
- Customer account
- reindeerFunc runs a ReindeerFunc
- oxy queue
LittleBookOfSemaphores Key Features
LittleBookOfSemaphores Examples and Code Snippets
Community Discussions
Trending Discussions on LittleBookOfSemaphores
QUESTION
I am currently trying to solve the 'unisex bathroom' problem found in [this book],(http://greenteapress.com/semaphores/LittleBookOfSemaphores.pdf) the constraints are: - if the bathroom is empty, either male or female can enter - if a male or female is in the bathroom, only the same gender can enter - there can only be two people in the bathroom already
What is confusing me is although I have some understanding of the concepts of how the logic works, I am not sure where/how to implement this code. Eg, I have a class named 'employee' which extends thread and can set a variable that shows if they are male or female. I also have a 'bathroom' class that also extends thread that contains the semaphore called 'being used' which is to determine if the bathroom is full. I was trying to implement the lightswitch structure found in the book, which i assume is just a monitor. I do not understand how this locks for a specific type of thread.
My question is, where do I store the semaphore variables, and what is the best way to access them in order to implement the rest of the logic?
EDIT: When I refer to the lightswitch I mean the struct on page 70, and the bathroom problem is located on page 170.
Bathroom class contains:
...ANSWER
Answered 2019-Oct-09 at 07:06Without reading the book... A semaphore belongs to the bathroom: if you had three bathrooms and seven users, you would have three semaphores, not one, not seven. A semaphore licence should be acquired whenever bathroom is applied for entrance by a user, and released whenever an exit message is sent to it, or an entering user is denied entry.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install LittleBookOfSemaphores
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page