Initializer Constructor.
Number of maximum sections acquirable.
Acquires a section.
Acquires a section until be released. If all of the sections in the smeaphore already have been acquired by others, the function call would be blocked until one of them returns its acquisition by calling the release method.
In same reason, if you don't call the release function after you business, the others who want to acquire a section from the semaphore would be fall into the forever sleep. Therefore, never forget to calling the release function or utilize the UniqueLock.lock function instead with {@link Semaphore.get_lockable} to ensure the safety.
Number of maximum sections acquirable.
Release sections.
When you call this release method and there're someone who are currently blocked by attemping to acquire a section from this semaphore, n of them (FIFO; first-in-first-out) would acquire those released sections and continue their executions.
Otherwise, there's not anyone who is acquiring the section or number of the blocked are less than n, the OutOfRange error would be thrown.
As you know, when you succeeded to acquire a section, you don't have to forget to calling this release method after your business. If you forget it, it would be a terrible situation for the others who're attempting to acquire a section from this semaphore.
However, if you utilize the UniqueLock with {@link Semaphore.get_lockable}, you don't need to consider about this release method. Just define your business into a callback function as a parameter of methods of the UniqueLock, then this release method would be automatically called by the UniqueLock after the business.
Number of sections to be released. Default is 1.
Tries to acquire a section.
Attempts to acquire a section without blocking. If succeeded to acquire a section from the
semaphore immediately, it returns true
directly. Otherwise all of the sections in the
semaphore are full, the function gives up the trial immediately and returns false
directly.
Note that, if you succeeded to acquire a section from the semaphore (returns `true) but do not call the release function after your business, the others who want to acquire a section from the semaphore would be fall into the forever sleep. Therefore, never forget to calling the release function or utilize the UniqueLock.try_lock function instead with {@link Semaphore.get_lockable} to ensure the safety.
Whether succeeded to acquire or not.
Tries to acquire a section until timeout.
Attempts to acquire a section from the semaphore until timeout. If succeeded to acquire a
section until the timeout, it returns true
. Otherwise failed to acquiring a section in
given the time, the function gives up the trial and returns false
.
Failed to acquiring a section in the given time (returns false
), it means that there're
someone who have already acquired sections and do not return them over the
time expiration.
Note that, if you succeeded to acquire a section from the semaphore (returns `true) but do not call the release function after your business, the others who want to acquire a section from the semaphore would be fall into the forever sleep. Therefore, never forget to calling the release function or utilize the {@link UniqueLock.try_acquire_for} function instead with {@link Semaphore.get_lockable} to ensure the safety.
The maximum miliseconds for waiting.
Whether succeded to acquire or not.
Tries to acquire a section until timeout.
Attempts to acquire a section from the semaphore until time expiration. If succeeded to
acquire a section until the time expiration, it returns true
. Otherwise failed to
acquiring a section in the given time, the function gives up the trial and returns false
.
Failed to acquiring a section in the given time (returns false
), it means that there're
someone who have already acquired sections and do not return them over the
time expiration.
Note that, if you succeeded to acquire a section from the semaphore (returns `true) but do not call the release function after your business, the others who want to acquire a section from the semaphore would be fall into the forever sleep. Therefore, never forget to calling the release function or utilize the {@link UniqueLock.try_acquire_until} function instead with {@link Semaphore.get_lockable} to ensure the safety.
The maximum time point to wait.
Whether succeded to acquire or not.
Generated using TypeDoc
Counting semaphore.
Jeongho Nam - https://github.com/samchon