From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10565 invoked by alias); 3 Mar 2003 10:02:15 -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 10551 invoked from network); 3 Mar 2003 10:02:14 -0000 Received: from unknown (HELO fernet.posam.sk) (62.168.66.66) by 172.16.49.205 with SMTP; 3 Mar 2003 10:02:14 -0000 Received: from smtpmta.posam.sk (smtpmta [172.16.0.6]) by fernet.posam.sk (Postfix) with ESMTP id 75C15192F2 for ; Mon, 3 Mar 2003 11:01:15 +0100 (CET) To: pthreads-win32@sources.redhat.com Subject: pthread_mutex_timedlock problem MIME-Version: 1.0 Message-ID: From: "Robert Strycek" Date: Mon, 03 Mar 2003 10:02:00 -0000 Content-Type: text/plain; charset="us-ascii" X-SW-Source: 2003/txt/msg00033.txt.bz2 Hello All, I'm working on an rw-mutex and found something like a dead lock when testing timed lock functions. To be sure, I wrote a simple test program, which hangs up, too. after ~4 loops it's dead (on 1GHz P3, Win2k) Here it is: #include #include #include "lib/pthreads/pthread.h" #define DELAY 200 #define _log(what) OutputDebugString( what ) pthread_mutex_t mut; void * thread_proc_w( void * ); int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { int i; pthread_t th_w[2]; pthread_mutexattr_t m; pthread_mutexattr_init( &m ); pthread_mutexattr_settype( &m, PTHREAD_MUTEX_NORMAL ); //PTHREAD_MUTEX_RECURSIVE pthread_mutex_init( &mut, &m ); pthread_mutexattr_destroy( &m ); for( i=0; i<2; i++ ) pthread_create( &th_w[i], NULL, thread_proc_w, (void *) i ); while( 1 ) Sleep( 1000 ); return 0; } void * thread_proc_w( void * param ) { timespec ts; _timeb tb; while( 1 ) { Sleep( 100 ); while( 1 ) { _ftime( &tb ); ts.tv_sec = DELAY/1000 + tb.time; ts.tv_nsec = (DELAY%1000 + tb.millitm) * 1000000; int ret = pthread_mutex_timedlock( &mut, &ts ); // this makes problems if( ret == 0 ) break; } _log( param ? "\r\nL0" : "\r\nL1" ); //I'm alive Sleep( 500 ); _log( param ? "u0" : "u1" ); //unlocking ... pthread_mutex_unlock( &mut ); } pthread_exit( 0 ); return 0; } ------------------------------- (values in Sleep() do matter - some values work fine) After a few loops, the mutex 'mut' cannot be locked no more. Does anyone have any idea what's wrong ? Thanks, Robo