From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32325 invoked by alias); 12 Jun 2006 12:27:17 -0000 Received: (qmail 32263 invoked by uid 22791); 12 Jun 2006 12:27:11 -0000 X-Spam-Check-By: sourceware.org Received: from efesto.telvia.it (HELO efesto.telvia.it) (213.155.209.50) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 12 Jun 2006 12:27:04 +0000 Received: from [213.155.203.226] (unverified [213.155.203.226]) by efesto.telvia.it (Vircom SMTPRS 5.3.228) with ESMTP id for ; Mon, 12 Jun 2006 14:27:20 +0200 Message-ID: <448D5D96.4070902@telvia.it> Date: Mon, 12 Jun 2006 12:27:00 -0000 From: Romano Paolo Tenca User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Pthreads-Win32 list Subject: pthread_cond_destroy and cancel Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact pthreads-win32-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: pthreads-win32-owner@sourceware.org X-SW-Source: 2006/txt/msg00038.txt.bz2 This code creates a thread and use 2 cond var to sincronize. Then the thread is cancelled and the thread hangs executing pthread_cond_destroy(&cv2). The output is main: sleeping forever thread: try to destroy cv2 Where is the problem? In my code or in pthread_cond_destroy with a deferred cancel pending? ----------------------------start of code -------------------------- #include #include #include #include /* * compiled with gcc version 3.2.3 (mingw special 20030504-1) * under XP Professional * linked with libpthreadGC2 2.7.0 prebuilt */ static pthread_cond_t cv1 = PTHREAD_COND_INITIALIZER; static pthread_mutex_t mutex1 = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER; static pthread_cond_t cv2 = PTHREAD_COND_INITIALIZER; static pthread_mutex_t mutex2 = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER; static void *func(void *arg){ int err; // signal cv1 pthread_mutex_lock(&mutex1); pthread_cond_signal(&cv1); pthread_mutex_lock(&mutex2); pthread_mutex_unlock(&mutex1); // wait cv2 pthread_cond_wait(&cv2, &mutex2); pthread_mutex_unlock(&mutex2); // to be sure that main calls cancel on this thread Sleep(50); //destroy mutex2 and cv2 printf("thread: try to destroy cv2\n"); err = pthread_cond_destroy(&cv2); printf("thread: cv2 err: %d\n",err); // bug? this is not executed pthread_mutex_destroy(&mutex2); return NULL; } void test(void){ int err; pthread_t pid; pthread_mutex_lock(&mutex1); // create thread pthread_create(&pid, NULL, func, NULL); // wait cv1 pthread_cond_wait(&cv1, &mutex1); pthread_mutex_lock(&mutex2); pthread_mutex_unlock(&mutex1); // signal cv2 pthread_cond_signal(&cv2); pthread_mutex_unlock(&mutex2); //cancel the thread err = pthread_cancel(pid); assert(err == 0); puts("main: sleeping forever"); Sleep(INFINITE); } int main(int argc, char **argv) { test(); return 0; } -- Romano Paolo Tenca