From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7168 invoked by alias); 11 Feb 2004 00:08:32 -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 7123 invoked from network); 11 Feb 2004 00:08:30 -0000 Received: from unknown (HELO mail.thelaststop.net) (209.42.38.167) by sources.redhat.com with SMTP; 11 Feb 2004 00:08:30 -0000 Received: from [192.168.1.150] (unknown [192.168.1.1]) by mail.thelaststop.net (Postfix) with ESMTP id 051AE84776 for ; Tue, 10 Feb 2004 19:08:28 -0500 (EST) Subject: pthread_cancel and pthread_mutex_lock From: Rian Hunter To: pthreads-win32@sources.redhat.com Content-Type: text/plain Message-Id: <1076458107.47098.14.camel@www.thelaststop.net> Mime-Version: 1.0 Date: Wed, 11 Feb 2004 00:08:00 -0000 Content-Transfer-Encoding: 7bit X-SW-Source: 2004/txt/msg00010.txt.bz2 Hello! >From reading the mailing list archives i found out that at one point in the pthreads-win32 library pthread_mutex_lock acted as a cancellation point, but since then that was removed. I have a thread that needs to be cancelled during a pthread_mutex_lock, so naturally i would have to set the cancel type to PTHREAD_CANCEL_ASYNCHRONOUS as per the new behavior. I'm not sure if pthread_mutex_lock can be asynchronously cancelled, but i'm having a problem with code similar to this: ------------------ #include #include pthread_mutex_t inputLock; void *t2(void *threadid) { pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); printf("created \n"); /* waits to be cancelled here */ pthread_mutex_lock(&inputLock); /* never gets here */ printf("dead\n"); return 0; } int main() { pthread_t sender; int i; /* initialize and lock mutex */ pthread_mutex_init(&inputLock, NULL); pthread_mutex_lock(&inputLock); pthread_create(&sender, NULL, t2, NULL); /* psuedo sleep function */ for(i = 0;i <10000000; i++) {} printf("slept and thread created\n"); /* cancel thread and wait for termination */ pthread_cancel(sender); pthread_join(sender, NULL); /* check if thread was cancelled */ printf("successfully canceled thread\n"); /* test lock for continued operation */ pthread_mutex_unlock(&inputLock); pthread_mutex_lock(&inputLock); /* signify correct execution */ printf("all done\n"); return 0; } ---------- On FreeBSD the code executes correctly, at least i assume it is the correct behavior of a pthreads implementation. On windows it just freezes after it prints "created". I appreciate any help! thank you! -rian