newbie question on threading

Aahz aahz at pythoncraft.com
Sun Oct 13 08:32:32 CEST 2002


In article <jsngquskdhc0cpg867djcna0cl6u8tlm9l at 4ax.com>,
Gonçalo Rodrigues  <op73418 at mail.telepac.pt> wrote:
>
>#Balancing act: We can't afford a pure busy loop, so we
>#have to sleep; but if we sleep the whole timeout time,
>#we'll be unresponsive.
>
>My question is: why is a busy loop not affordable (without a sleep
>call), e.g. something like (in pseudo-code description)
>
>while 1:
>    <acquire lock>
>    if <acquire sucessfull>:
>        break
>    if <timedout?>:
>        break
>    <calculate endtime>

Consider this:

    while 1:
        pass

Given the above loop in a thread, how much useful work is the thread
doing?  Not much, right?  Well, adding an "if" statement to the loop
doesn't do any good for producing useful work.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/



More information about the Python-list mailing list