Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How can I force thread switching?

by Grimy (Monk)
on Sep 28, 2013 at 15:29 UTC ( #1056144=note: print w/ replies, xml ) Need Help??


in reply to How can I force thread switching?

In Java, calling Thread.yield() (or, alternatively, Thread.sleep(0)) does what you want. Iím not sure how to do the equivalent in Perl, but if sleeping for one micro-second is more acceptable, you may want to look at Time::HiRes.


Comment on Re: How can I force thread switching?
Select or Download Code
Re^2: How can I force thread switching?
by ajl52 (Novice) on Sep 28, 2013 at 15:41 UTC

    I have already explored Time::HiRes since usleep() is defined in this package.

    I also attempted to wait for 0 unit of time (second or microsecond) to no avail. The null delay is probably detected somewhere and optimised out.

    As stated in the manual, yield() is a no-op on most systems.

      I also attempted to wait for 0 unit of time (second or microsecond) to no avail. The null delay is probably detected somewhere and optimised out.

      BrowserUk says yield is a mistake (like sleep 0), so sleep more, like 1/2 (or less) of the minimum time period that you believe it will take, like 33 milliseconds -- seems to hold true on win32, good rule of thumb :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1056144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-27 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (232 votes), past polls