in reply to Re: Perl threads: using yield() and Time::HiRes usleep() in Linux/*nix
in thread Perl threads: using yield() and Time::HiRes usleep() in Linux/*nix
sleep and yield both take the thread off the cpu. If priorities are involved (which they prolly are not in this) then the thread that yields could get put back on immediatly. the sleeping thread will wait until it is woken up at the end of its time. so both should accomplish the goal giving up the cpu, the sleep just wastes a lot processor time. If only one thread is running then you have to wait all that time with the cpu at 0%. yield should give everyone else a chance then come back ASAP. Well it depends on the schedluer of course, but linux is smart