.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "SemaphoreSet 3pm" .TH SemaphoreSet 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Coro::SemaphoreSet \- efficient set of counting semaphores .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Coro; \& \& $sig = new Coro::SemaphoreSet [initial value]; \& \& $sig\->down ("semaphoreid"); # wait for signal \& \& # ... some other "thread" \& \& $sig\->up ("semaphoreid"); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module implements sets of counting semaphores (see Coro::Semaphore). It is nothing more than a hash with normal semaphores as members, but is more efficiently managed. .PP This is useful if you want to allow parallel tasks to run in parallel but not on the same problem. Just use a SemaphoreSet and lock on the problem identifier. .PP You don't have to load \f(CW\*(C`Coro::SemaphoreSet\*(C'\fR manually, it will be loaded automatically when you \f(CW\*(C`use Coro\*(C'\fR and call the \f(CW\*(C`new\*(C'\fR constructor. .IP "new [initial count]" 4 .IX Item "new [initial count]" Creates a new semaphore set with the given initial lock count for each individual semaphore. See Coro::Semaphore. .ie n .IP "$semset\->down ($id)" 4 .el .IP "\f(CW$semset\fR\->down ($id)" 4 .IX Item "$semset->down ($id)" Decrement the counter, therefore "locking" the named semaphore. This method waits until the semaphore is available if the counter is zero. .ie n .IP "$semset\->up ($id)" 4 .el .IP "\f(CW$semset\fR\->up ($id)" 4 .IX Item "$semset->up ($id)" Unlock the semaphore again. If the semaphore reaches the default count for this set and has no waiters, the space allocated for it will be freed. .ie n .IP "$semset\->try ($id)" 4 .el .IP "\f(CW$semset\fR\->try ($id)" 4 .IX Item "$semset->try ($id)" Try to \f(CW\*(C`down\*(C'\fR the semaphore. Returns true when this was possible, otherwise return false and leave the semaphore unchanged. .ie n .IP "$semset\->count ($id)" 4 .el .IP "\f(CW$semset\fR\->count ($id)" 4 .IX Item "$semset->count ($id)" Return the current semaphore count for the specified semaphore. .ie n .IP "$semset\->waiters ($id)" 4 .el .IP "\f(CW$semset\fR\->waiters ($id)" 4 .IX Item "$semset->waiters ($id)" Returns the number (in scalar context) or list (in list context) of waiters waiting on the specified semaphore. .ie n .IP "$semset\->wait ($id)" 4 .el .IP "\f(CW$semset\fR\->wait ($id)" 4 .IX Item "$semset->wait ($id)" Same as Coro::Semaphore::wait on the specified semaphore. .ie n .IP "$guard = $semset\->guard ($id)" 4 .el .IP "\f(CW$guard\fR = \f(CW$semset\fR\->guard ($id)" 4 .IX Item "$guard = $semset->guard ($id)" This method calls \f(CW\*(C`down\*(C'\fR and then creates a guard object. When the guard object is destroyed it automatically calls \f(CW\*(C`up\*(C'\fR. .ie n .IP "$semaphore = $semset\->sem ($id)" 4 .el .IP "\f(CW$semaphore\fR = \f(CW$semset\fR\->sem ($id)" 4 .IX Item "$semaphore = $semset->sem ($id)" This SemaphoreSet version is based on Coro::Semaphore's. This function creates (if necessary) the underlying Coro::Semaphore object and returns it. You may legally call any Coro::Semaphore method on it, but note that calling \f(CW\*(C`$semset\->up\*(C'\fR can invalidate the returned semaphore. .SH AUTHOR/SUPPORT/CONTACT .IX Header "AUTHOR/SUPPORT/CONTACT" .Vb 2 \& Marc A. Lehmann \& http://software.schmorp.de/pkg/Coro.html .Ve