Return-Path: william@bourbon.usc.edu Delivery-Date: Sun Sep 21 21:07:04 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 m8M474BX019214 for ; Sun, 21 Sep 2008 21:07:04 -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 m8M49La6008448 for ; Sun, 21 Sep 2008 21:09:21 -0700 Message-Id: <200809220409.m8M49La6008448@bourbon.usc.edu> To: cs551@merlot.usc.edu Subject: Re: CS551 - Prj2 - Signal Handling Date: Sun, 21 Sep 2008 21:09:21 -0700 From: Bill Cheng SOmeone wrote: > When we catch a SIGINT, one of the threads might output the data > after all the statistics is printed out (since I am using a mutex > for stdout it will not be interleaved ... but after all the > statistics, the simulation data is printed) ... I can stop it by > calling exit() but then it will not be graceful anymore. At > present I am just setting a flag which all the threads check. > Should I use exit() ? You should make sure that output are done in the correct order. Your main thread should wait for all child threads to finish by calling pthread_join(). After that, it should print statistics. Personally, I would never call exit() unless I have to exit abruptly. For example, when malloc() fails, there's really no point to clean up. So, calling exit() is fine. Also, if there is a problem initializing your program and before anything serious has started, you can call exit(). -- Bill Cheng // bill.cheng@usc.edu