public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Robert Strycek" <strycek@posam.sk>
To: pthreads-win32@sources.redhat.com
Subject: pthread_mutex_timedlock problem
Date: Mon, 03 Mar 2003 10:02:00 -0000	[thread overview]
Message-ID: <OFDD816DD5.FA929D2C-ONC1256CDE.003715FC-C1256CDE.003721C7@posam.sk> (raw)

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 <windows.h>
#include <sys/timeb.h>
#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

             reply	other threads:[~2003-03-03 10:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-03 10:02 Robert Strycek [this message]
2003-03-03 16:39 ` Alexander Terekhov
2003-03-04  0:56   ` Ross Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=OFDD816DD5.FA929D2C-ONC1256CDE.003715FC-C1256CDE.003721C7@posam.sk \
    --to=strycek@posam.sk \
    --cc=pthreads-win32@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).