#!/usr/bin/perl - use strict; use warnings; use threads; use threads::shared; my $locked :shared; lock($locked); print "locked(main)\n "; my $thr = async( sub { test() } ); print "starting\n"; my $wait = time() + 15; until ( my $ok = lock($locked) ) { last if !cond_timedwait( $locked, $wait ); } print "result: timeout\n" if defined $wait; print "done\n"; exit; sub test { print "started. \n"; lock($locked); print "lock(test)\n "; sleep 10; print "exiting\n"; { no warnings 'threads'; cond_signal($locked); } }
In reply to Re: threads - cond_timedwait question
by Khen1950fx
in thread threads - cond_timedwait question
by ethrbunny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |