-
For I think, Or there exists some case i do not know. please correct me if wrong. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
That code is checking to see if the current task owns the semaphore and releases it only if it does. It is a little confusing because it uses a |
Beta Was this translation helpful? Give feedback.
-
How ? UPDATE: Oh, I know, i think this it is |
Beta Was this translation helpful? Give feedback.
That code is checking to see if the current task owns the semaphore and releases it only if it does.
It is a little confusing because it uses a
MutableInt
as a reference count. Originally it was intended that we would reference count how many times we asked to grab the semaphore and only release it when we hit the same number, but that proved to be impossible, so now the value of the reference count is always 1 or 0. It goes to 1 when a task grabs the semaphore and goes to 0 when it releases the semaphore. Al other times the code looks to see if the task already has the semaphore and lets it through, or the release becomes a noop.