a) print "ok $var\n"; $var++ isn't atomic by any stretch of imagination
b) $var++ is not atomic
c) the creating of the string to print and the actuall printing
could be preempted by another thread
p4raw-id: //depot/perl@16450
my $test : shared = 1;
+sub ok {
+ lock($test);
+ print "ok $test\n";
+ $test++;
+}
+
sub reader {
my $tid = threads->self->tid;
my $i = 0;
$i++;
# print "reader (tid $tid): waiting for element $i...\n";
my $el = $q->dequeue;
- print "ok $test\n"; $test++;
+ ok();
+# print "ok $test\n"; $test++;
# print "reader (tid $tid): dequeued element $i: value $el\n";
select(undef, undef, undef, rand(1));
if ($el == -1) {
# print "waiting for join\n";
$_->join();
}
-print "ok $test\n";
+ok();
+#print "ok $test\n";