in reply to Re^17: Threads sharing global variable (disingenous)
in thread Threads sharing global variable

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); } }