Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I would expect all "next" times to be higher than "first" times (unless I messed it with semaphores), but on some invocations it is not the case. Why does this happen? This is Strawberry 5.42
use strict; use warnings; no warnings 'void'; use threads; use Thread::Semaphore ; use Time::HiRes 'time'; my $t = time; my @s = map Thread::Semaphore-> new( 0 ), 1 .. 4; my @t = map async { my $id = threads-> tid - 1; $s[ $id ]-> down; sin for 1 .. 1e7; # work per thread printf "first, %d %.3f\n", $id, time - $t; $s[ $id ]-> up( 4 ); $_-> down for @s; printf "next, %d %.3f\n", $id, time - $t; }, 1 .. 4; sin for 1 .. 1e7; # initial work $_-> up for @s; $_-> join for @t; __END__ first, 2 1.824 first, 3 1.824 first, 1 1.824 first, 0 1.832 next, 1 1.826 next, 3 1.828 next, 2 1.832 next, 0 1.832
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is it OK for Time::HiRes::time() to report the time differently per thread?
by Anonymous Monk on Apr 23, 2026 at 13:03 UTC | |
by ikegami (Patriarch) on Apr 23, 2026 at 16:26 UTC | |
|
Re: Is it OK for Time::HiRes::time() to report the time differently per thread?
by ikegami (Patriarch) on Apr 23, 2026 at 16:15 UTC | |
by Anonymous Monk on Apr 23, 2026 at 19:30 UTC | |
|
Re: Is it OK for Time::HiRes::time() to report the time differently per thread?
by Corion (Patriarch) on Apr 23, 2026 at 13:00 UTC | |
by ikegami (Patriarch) on Apr 23, 2026 at 16:28 UTC | |
|
Re: Is it OK for Time::HiRes::time() to report the time differently per thread?
by ikegami (Patriarch) on Apr 23, 2026 at 15:52 UTC |