9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] alarm() and threads..
@ 2005-12-06 22:16 ISHWAR RATTAN
  2005-12-06 22:24 ` Russ Cox
  0 siblings, 1 reply; 6+ messages in thread
From: ISHWAR RATTAN @ 2005-12-06 22:16 UTC (permalink / raw)
  To: 9fans

What is the behavior of using alarm() in one of the threads
in a multi-threaded program? Which will thread will get the
note? Or it is undefined -- alarm() can be used at process
level.

Also, where can I find sample code to handle terminal
abort/interrupt?

-ishwar


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

* Re: [9fans] alarm() and threads..
  2005-12-06 22:16 [9fans] alarm() and threads ISHWAR RATTAN
@ 2005-12-06 22:24 ` Russ Cox
  2005-12-07 14:29   ` ISHWAR RATTAN
  0 siblings, 1 reply; 6+ messages in thread
From: Russ Cox @ 2005-12-06 22:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> What is the behavior of using alarm() in one of the threads
> in a multi-threaded program? Which will thread will get the
> note?

Threads don't get notes.  Processes do.  The function you
register with threadnotify will run in the same proc that
got the note, and if that proc was in a system call, that
system call will have been interrupted, regardless of which
thread inside the proc was running the system call.

If your code looks like:

    alarm(10);
    read();
    alarm(0);

then you can be sure that your thread's read is the one that
will be interrupted should the alarm go off.

> Also, where can I find sample code to handle terminal
> abort/interrupt?

Depends on what you mean by this.  If you mean when
the user types Delete to kill a program, that turns into
a "interrupt" note.

Russ


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

* Re: [9fans] alarm() and threads..
  2005-12-06 22:24 ` Russ Cox
@ 2005-12-07 14:29   ` ISHWAR RATTAN
  2005-12-07 14:32     ` Russ Cox
  0 siblings, 1 reply; 6+ messages in thread
From: ISHWAR RATTAN @ 2005-12-07 14:29 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



On Tue, 6 Dec 2005, Russ Cox wrote:

> Depends on what you mean by this.  If you mean when
> the user types Delete to kill a program, that turns into
> a "interrupt" note.

How can it be acheived in context in writing a program
to handle this condition?

-ishwar



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

* Re: [9fans] alarm() and threads..
  2005-12-07 14:29   ` ISHWAR RATTAN
@ 2005-12-07 14:32     ` Russ Cox
  2005-12-07 17:11       ` ISHWAR RATTAN
  0 siblings, 1 reply; 6+ messages in thread
From: Russ Cox @ 2005-12-07 14:32 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> > Depends on what you mean by this.  If you mean when
> > the user types Delete to kill a program, that turns into
> > a "interrupt" note.
>
> How can it be acheived in context in writing a program
> to handle this condition?

What do you want the program to do when the user types Delete?

Russ


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

* Re: [9fans] alarm() and threads..
  2005-12-07 14:32     ` Russ Cox
@ 2005-12-07 17:11       ` ISHWAR RATTAN
  2005-12-07 18:43         ` Russ Cox
  0 siblings, 1 reply; 6+ messages in thread
From: ISHWAR RATTAN @ 2005-12-07 17:11 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs



On Wed, 7 Dec 2005, Russ Cox wrote:

> What do you want the program to do when the user types Delete?
Generally a clean up, closing open files etc.

-ishwar


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

* Re: [9fans] alarm() and threads..
  2005-12-07 17:11       ` ISHWAR RATTAN
@ 2005-12-07 18:43         ` Russ Cox
  0 siblings, 0 replies; 6+ messages in thread
From: Russ Cox @ 2005-12-07 18:43 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> > What do you want the program to do when the user types Delete?
> Generally a clean up, closing open files etc.

Then install a handler with threadnotify
and have it clean up if strcmp(note, "interrupt")==0.

Russ


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

end of thread, other threads:[~2005-12-07 18:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-06 22:16 [9fans] alarm() and threads ISHWAR RATTAN
2005-12-06 22:24 ` Russ Cox
2005-12-07 14:29   ` ISHWAR RATTAN
2005-12-07 14:32     ` Russ Cox
2005-12-07 17:11       ` ISHWAR RATTAN
2005-12-07 18:43         ` 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).