Look for a good analogy / examples for semaphore

The monitor should solve problems with semaphores in parallel environments.
I am looking for a good analogy using a semaphore using stickers.

Please use the information by analogy:
4 tasks (TaskA, TaskB, TaskC, TaskD)
1 varX variable

Each task wants to manipulate varX based on an event.

+2
source share
3 answers

Let's say that a group of patients wants to see a doctor.

, , , , , .

, , - , , .

, , .

+6

. - , , - (.. ). () (wait()). , , , .

. , . (wait()), (()), . , .

: www.mijnadres.net/published/Monitor%20Object%20Pattern.pdf

+2

It is important to highlight resource competition from event notification. Monitor and Semaphore are used to restrict access to a shared resource. A monitor is basically a semaphore whose score is 1. If each of your tasks wants to access one varX, you need to protect it with your monitor (or sempahore from 1):

Monitor.Enter 
// do something with varX
Monitor.Exit

or

Semaphore.Acquire
// do something with varX
Semaphore.Release

Using Semaphore, you can obviously set the number of allowed concretization participants for a shared resource.

Nick.

+1
source

All Articles