From: Joel Salomon <chesky@plan9.jp>
To: 9fans@cse.psu.edu
Subject: [9fans] Interrupted alarm(2)
Date: Tue, 12 Dec 2006 22:39:25 -0500 [thread overview]
Message-ID: <68313859d562920ef34e99b7dc1a4046@plan9.jp> (raw)
I’ve been simulating preemptive multithreading using alarm(2) notes
and lots of stack smashing. (I’ll have some questions about that
later, if things don’t go smooth.)
Anyhow, my taskfork looks like:
void
taskfork(ulong flags)
{
long quantum;
...
quantum = alarm(0); // stop timer and save time left
...
// back to our regularly scheduled programming...
alarm(quantum == 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
next reply other threads:[~2006-12-13 3:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-13 3:39 Joel Salomon [this message]
2006-12-13 4:13 ` Russ Cox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68313859d562920ef34e99b7dc1a4046@plan9.jp \
--to=chesky@plan9.jp \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).