This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

1.3.12: pthread mutex - second lock won't block.


hi,

If I lock a fast mutex twice, it normaly should block forever. But I
can't reproduce that behavior under the current cygwin version. The
mutex won't block after the second lock. The behavior under cygwin
is similar to a recursive mutex. What's wrong?


Test.c:
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
/* gcc -Wall -lpthread test.c -o test */

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#define __USE_GNU
#include <pthread.h>

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

int main (void)
{
   int ret;

   if ((ret = pthread_mutex_lock (&lock)) != 0)
   {
      printf ("pthread_mutex_lock (): %s\n", strerror (ret));
      return EXIT_FAILURE;
   }

   if ((ret = pthread_mutex_lock (&lock)) != 0)
   {
      printf ("pthread_mutex_lock (): %s\n", strerror (ret));
      return EXIT_FAILURE;
   }

   printf ("DEADBEEF!\n");

   return EXIT_SUCCESS;
}
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=



Under Linux and SunOS the second lock will cause a deadlock.
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
zero:~$ uname -a
Linux foo 2.4.18 #1 Thu Jul 4 22:49:55 CEST 2002 i686 unknown
zero:~$ /lib/libc.so.6 | head -1
GNU C Library stable release version 2.2.5, by Roland McGrath et al.
zero:~$ gcc -Wall -lpthread test.c -o test
zero:~$ ./test

zero:~> uname -sr
SunOS 5.6
zero:~> gcc -Wall -lpthread test.c -o test
zero:~> ./test

-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=



Under cygwin the second lock will not block.
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=
~$ uname -a
CYGWIN_98-4.10 GADGET 1.3.12(0.54/3/2) 2002-07-03 16:42 i686 unknown
~$ gcc -Wall -lpthread test.c -o test
~$ ./test.exe
DEADBEEF!
~$
-=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-= -=-=

-- 
:)


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]