From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <68313859d562920ef34e99b7dc1a4046@plan9.jp> To: 9fans@cse.psu.edu From: Joel Salomon Date: Tue, 12 Dec 2006 22:39:25 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Subject: [9fans] Interrupted alarm(2) Content-Transfer-Encoding: quoted-printable Topicbox-Message-UUID: f3907acc-ead1-11e9-9d60-3106f5b1d025 I=E2=80=99ve been simulating preemptive multithreading using alarm(2) not= es and lots of stack smashing. (I=E2=80=99ll have some questions about that later, if things don=E2=80=99t go smooth.) Anyhow, my taskfork looks like: void taskfork(ulong flags) { long quantum; ... quantum =3D alarm(0); // stop timer and save time left ... // back to our regularly scheduled programming... alarm(quantum =3D=3D 0 ? 1 : quantum); } I included that ugly last line on the off chance that taskfork() is called with less than a millisecond left and so alarm(0) will return 0. Is this neccessary, or can alarm(0) not ever return 0? Would it be better to write: if(quantum) alarm(quantum); else postnote(PNPROC, getpid(), "alarm"); } --Joel