From c23504631008ce0bfaa5bec48acb2b04f4b49fd9 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 10 Aug 2015 03:48:37 +0200 Subject: libthread: use "interrupt" proc ctl message instead of posting a note for threadint() threadint() is called to interrupt channel operation or a system call. the kernel provides a new "interrupt" procctl message to interrupt a process commited to or being in a blocking syscall, which is similar, but not the same. the main difference is that "interrupt" condition is not cleared before the process actually attempts to block. also can be cleared with "nointerrupt" ctl message. see proc(3) --- sys/src/libthread/kill.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'sys/src/libthread/kill.c') diff --git a/sys/src/libthread/kill.c b/sys/src/libthread/kill.c index 46c442066..9160df016 100644 --- a/sys/src/libthread/kill.c +++ b/sys/src/libthread/kill.c @@ -79,8 +79,20 @@ threadint(int id) static void tinterrupt(Proc *p, Thread *t) { + char buf[64]; + int fd; + switch(t->state){ case Running: + snprint(buf, sizeof(buf), "/proc/%d/ctl", p->pid); + fd = open(buf, OWRITE|OCEXEC); + if(fd >= 0){ + if(write(fd, "interrupt", 9) == 9){ + close(fd); + break; + } + close(fd); + } postnote(PNPROC, p->pid, "threadint"); break; case Rendezvous: -- cgit v1.2.3