L
L
libroten2021-06-16 22:14:44
Multithreading
libroten, 2021-06-16 22:14:44

In what situations is it necessary to use a NOT binary semaphore?

I can’t find examples of tasks when there is a need to use a semaphore with an initial counter value greater than 1.
Everywhere they write that such a semaphore is needed in situations where we have a certain number of units of some resource, and the initial value of the semaphore counter should be set equal to the number of units of this resource.
But it is not very clear what kind of resources these could be, I would like to see examples.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vorfall, 2021-06-17
@Vorfall

for example, when the semaphore serves in 2 directions (so that the amount of the resource or something does not exceed 0 and not more than the maximum)
, you conditionally process the amount of potatoes in the bucket,
you need the process to go on while the potatoes are in the bucket (the semaphore counter > 0 otherwise the process stops) or until the potatoes start to fall out of the bucket

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question