9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Interrupted alarm(2)
@ 2006-12-13  3:39 Joel Salomon
  2006-12-13  4:13 ` Russ Cox
  0 siblings, 1 reply; 2+ messages in thread
From: Joel Salomon @ 2006-12-13  3:39 UTC (permalink / raw)
  To: 9fans

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-12-13  4:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-13  3:39 [9fans] Interrupted alarm(2) Joel Salomon
2006-12-13  4:13 ` Russ Cox

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).