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

In reply to Is it OK for Time::HiRes::time() to report the time differently per thread? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.