[M3devel] variations of waitpid..?

Mika Nystrom mika at async.caltech.edu
Mon Jan 5 19:18:57 CET 2009


Jay writes:
>--_5fe387c0-3f5b-4882-b57b-b7299ded497e_
...
> much shorter.
>You know=2C the sequence is like:
>   fork/exec=20
>   run through a /little/ bit of code=20
> label=20
>   check if process done=20
>   if not
>     "sleep" (actual a call into the m3 scheduler which will run other thre=
>ads=20
>      goto label=20
>=20
...

You're right, but under user threads, here's what can (and does) happen,
e.g., in the compiler itself:

- Start child process
- Call Process.Wait, which...
   - Calls Thread.Pause(somesmallnumber)

There are no runnable threads, so the runtime yields the processor. 
I think it calls Unix's sleep?

The OS scheduler then schedules the process at a very low priority.
In most OSes, processes waiting for I/O have the highest priority,
and processes sleeping have the lowest.  So you've gone from waiting
for a process to exit, at high priority, to sleeping, at very low
priority.  The OS then takes its time to get around to waking you
up again.

This is my theory of what happens on FreeBSD anyhow.  It is the way
I describe my experimental result that you can change that sleep
to anything and it doesn't run noticeably faster than with 0.1d0.
Getting rid of the Thread.Pause speeds things up substantially :-)

     Mika





More information about the M3devel mailing list