Return-Path: william@bourbon.usc.edu Delivery-Date: Sun Oct 12 19:15:53 2008 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on merlot.usc.edu X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from bourbon.usc.edu (bourbon.usc.edu [128.125.9.75]) by merlot.usc.edu (8.14.1/8.14.1) with ESMTP id m9D2Fr8l027262 for ; Sun, 12 Oct 2008 19:15:53 -0700 Received: from bourbon.usc.edu (localhost.localdomain [127.0.0.1]) by bourbon.usc.edu (8.14.2/8.14.1) with ESMTP id m9D2NEmC021377 for ; Sun, 12 Oct 2008 19:23:14 -0700 Message-Id: <200810130223.m9D2NEmC021377@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CS 551 final 1 Date: Sun, 12 Oct 2008 19:23:14 -0700 From: Bill Cheng Someone wrote: > I am using a SIGUSR1 for terminating the sleeping thread. It works fine for > the case of 2 beacon nodes. > > When I run 3 beacon nodes, one of the processes terminates with a > message "*User > Signal 1*". All we are doing after catching the SIGUSR1 is setting a flag > and making the sleeping thread check that flag and exit. > > Also, we are sending the sleeping thread a signal by using the following > command: "*pthread_kill(threadid , SIGUSR1)*" > > When does a program terminate with a "*User Signal 1*" message ? I think it means you have received a SIGUSR1 signal and it's not caught! I think on Solaris, if you want to catch the same signal by the same signal handler after it's caught, you should call signal() again in side the signal handler. On Linux, you don't need to do this, I think. -- Bill Cheng // bill.cheng@usc.edu On Sun, Oct 12, 2008 at 8:19 AM, Bill Cheng wrote: > Someone wrote: > > > Its mentioned in the FAQ that: > > > > *" .........Please note that nodes X and Y will create a child thread > each > > to handle the other end of these connections. At the same time, node X > will > > terminate the 2nd child thread that's sleeping for 30 seconds and node Y > > will terminate the child thread that's sleeping for 30 seconds*." > > > > My question is, can we terminate the sleeping threads with a SIGKILL or > > should we handle it with SIGTERM ? > > You can use SIGTERM, SIGINT, or any signal to wake up this > thread and have this thread checking a flag to see if it's > time to terminate. > > > Basically, can we do a "forceful" termination ? > > You will never get an "yes" from me for something like this! :-) > > The way you *should* write code is to have only one exit > point for any thread. I think this is the first thing you > need to try to get good at. After you get really good at > this, you can do it other ways. Pthread has functions that > you can use to kill a thread. But you need to be very > careful when to do it and how to clean up whatever a thread > might left behind. > -- > Bill Cheng // bill.cheng@usc.edu