Thread::Semaphore - thread-safe semaphores
use Thread::Semaphore;
my $s = new Thread::Semaphore;
$s->down; # Also known as the semaphore P operation.
# The guarded section is here
$s->up; # Also known as the semaphore V operation.
# The default semaphore value is 1.
my $s = new Thread::Semaphore($initial_value);
$s->down($down_value);
$s->up($up_value);
Semaphores don't limit their values to zero or one, so they can be used to control access to some resource that there may be more than one of. (For example, filehandles.) Increment and decrement amounts aren't fixed at one either, so threads can reserve or return multiple resources at once.
This is the semaphore ``P operation'' (the name derives from the Dutch word ``pak'', which means ``capture'' --- the semaphore operations were named by the late Dijkstra, who was Dutch).
This is the semaphore ``V operation'' (the name derives from the Dutch word ``vrij'', which means ``release'').
|
Закладки на сайте Проследить за страницей |
Created 1996-2025 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |