From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18121 invoked by alias); 29 Sep 2005 16:13:12 -0000 Mailing-List: contact pthreads-win32-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sources.redhat.com Received: (qmail 18095 invoked by uid 22791); 29 Sep 2005 16:13:05 -0000 Received: from opterone.unito.it (HELO mail-out.unito.it) (130.192.119.88) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 29 Sep 2005 16:13:05 +0000 Received: (from root@localhost) by mail-out.unito.it (8.12.3/8.12.3/Debian -4) id j8TGD36H000787 for ; Thu, 29 Sep 2005 18:13:03 +0200 Received: from webservices.unito.it (webservices.unito.it [130.192.119.81]) by mail-out.unito.it (8.12.3/8.12.3/Debian -4) with ESMTP id j8TGD1SL000738 for ; Thu, 29 Sep 2005 18:13:01 +0200 Received: from 130.192.136.198 (SquirrelMail authenticated user lfu); by webservices.unito.it with HTTP; Thu, 29 Sep 2005 18:12:59 +0200 (CEST) Message-ID: <32883.130.192.136.198.1128010379.squirrel@130.192.136.198> Date: Thu, 29 Sep 2005 16:13:00 -0000 Subject: A question about thread cancellation From: "Fu Limin" To: pthreads-win32@sources.redhat.com Reply-To: limin.fu@ircc.it User-Agent: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Inrete-Amavisjob-Virus-Scanned: PDAmail Multiple Antivirus with ClamAv X-Inrete-Amavisjob-Service-Runned: 6 (j8TGD1SL000738) X-Inrete-Amavisjob-Service-Disabled: No Service disabled (j8TGD1SL000738) X-SW-Source: 2005/txt/msg00123.txt.bz2 Hello, I have a question on thread cancellation, which is not specifically relevant to pthread-win32, I hope you will not mind if I post it in this mailling list. In my program, there is a global mutex and a condition variable. And there are several threads wait on this cond.var. under the protection of this mutex. When I cancel one of the threads, I found there is a trouble in the thread clean up. Because the mutex can be in either locked or unlocked state. And if it is in locked state, I can't tell if it is locked by another thread, or it gets the locked state from the cancellation point pthread_cond_wait()! If it is locked by another thread, I should do nothing on it, but if it gets the locked state by returning from pthread_cond_wait() due to cancellation, I should unlock it in the clean up. So the problem is, how can I know, in the clean up, when should I unlock the mutex, and when not? Did any body have experienced similar problem? Does anybody have any hints on this? Thanks a lot!!! Limin