CORBA-omniORB
view release on metacpan or search on metacpan
omnithreads/shared/shared.pm view on Meta::CPAN
=item cond_wait CONDVAR, LOCKVAR
The C<cond_wait> function takes a B<locked> variable as a parameter,
unlocks the variable, and blocks until another thread does a
C<cond_signal> or C<cond_broadcast> for that same locked variable.
The variable that C<cond_wait> blocked on is relocked after the
C<cond_wait> is satisfied. If there are multiple threads
C<cond_wait>ing on the same variable, all but one will reblock waiting
to reacquire the lock on the variable. (So if you're only using
C<cond_wait> for synchronisation, give up the lock as soon as
possible). The two actions of unlocking the variable and entering the
blocked wait state are atomic, the two actions of exiting from the
blocked wait state and relocking the variable are not.
In its second form, C<cond_wait> takes a shared, B<unlocked> variable
followed by a shared, B<locked> variable. The second variable is
unlocked and thread execution suspended until another thread signals
the first variable.
It is important to note that the variable can be notified even if
omnithreads/shared/t/wait.t view on Meta::CPAN
"repeat", # cond var == lock var; explicit lock; e.g.: cond_wait($c, $c)
"twain" # cond var != lock var; explicit lock; e.g.: cond_wait($c, $l)
);
SYNC_SHARED: {
my $test : shared; # simple|repeat|twain
my $cond : shared;
my $lock : shared;
print "# testing my \$var : shared\n";
ok(1, 1, "Shared synchronization tests preparation");
$Base += 1;
sub signaller {
ok(2,1,"$test: child before lock");
$test =~ /twain/ ? lock($lock) : lock($cond);
ok(3,1,"$test: child obtained lock");
if ($test =~ 'twain') {
no warnings 'threads'; # lock var != cond var, so disable warnings
cond_signal($cond);
} else {
( run in 0.394 second using v1.01-cache-2.11-cpan-0d8aa00de5b )