I forgot to place the lock back inside the while loop. Sorry about that. The + 1 is necessary to not have double zeros in the output.
sub set_positive { while (1) { lock $a; if ($a == 0) { $a = int(rand() * 100) + 1; $q->enqueue($a); print "At set_positive: $a\n"; } else { cond_wait($a) } cond_broadcast($a); } }
In reply to Re^18: Threads sharing global variable (disingenous)
by Anonymous Monk
in thread Threads sharing global variable
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |