+ if((th->os_thread==tid) && (th->state != STATE_DEAD)) {
+ /* In clone_threads, if A and B both interrupt C at approximately
+ * the same time, it does not matter: the second signal will be
+ * masked until the handler has returned from the first one.
+ * In pthreads though, we can't put the knowledge of what function
+ * to call into the siginfo, so we have to store it in the
+ * destination thread, and do it in such a way that A won't
+ * clobber B's interrupt. Hence this stupid linked list.
+ *
+ * This does depend on SIG_INTERRUPT_THREAD being queued
+ * (as POSIX RT signals are): we need to keep
+ * interrupt_fun data for exactly as many signals as are
+ * going to be received by the destination thread.
+ */
+ struct cons *c;
+ int kill_status;
+ /* mask the signals in case this thread is being interrupted */
+ sigset_t newset,oldset;
+ sigemptyset(&newset);
+ sigaddset_blockable(&newset);
+ thread_sigmask(SIG_BLOCK, &newset, &oldset);
+
+ get_spinlock(&th->interrupt_fun_lock,
+ (int)arch_os_get_current_thread());
+ kill_status=thread_kill(th->os_thread,SIG_INTERRUPT_THREAD);
+ if(kill_status==0) {
+ c=alloc_cons(function,th->interrupt_fun);
+ th->interrupt_fun=c;
+ }
+ release_spinlock(&th->interrupt_fun_lock);
+ thread_sigmask(SIG_SETMASK,&oldset,0);
+ return (kill_status ? -1 : 0);
+ }