[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

small patch



Hi

I would like to discuss the nptl tst-mutex4.c and tst-rwlock4.c tests.

In both cases, the test: 
-> creates a process shared lock located in shared memory
-> takes the lock
-> forks
-> the child process unlocks the lock.

I would like to know whether you assume that the child owns the lock or
not. The only thing I could find in POSIX is in fork() description:

"A process shall be created with a single thread. If a multi-threaded
process calls fork(), the new process shall contain a replica of the
calling thread and its entire address space, possibly including the
states of mutexes and other resources."

I don't know if "states of mutexes" means: 'the mutex is owned by me' or
'the mutex is owned by thread XXX in process YYY'. In the first case
does that mean that there are two owners of the lock at the same time
after the fork? In the second case, the tests are not POSIX compliant,
so I submit an attached patch to make it clear in the comments.

Regards


-- 
Sébastien DECUGIS
Bull S.A.
diff -Nur libc-ori/nptl/tst-mutex4.c libc-new/nptl/tst-mutex4.c
--- libc-ori/nptl/tst-mutex4.c	2004-03-25 10:34:47.784741176 +0100
+++ libc-new/nptl/tst-mutex4.c	2004-03-25 10:39:34.231194696 +0100
@@ -17,6 +17,8 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+/* This is a test for behavior not guaranteed by POSIX.  */
+
 #include <errno.h>
 #include <pthread.h>
 #include <stdint.h>
@@ -164,7 +166,9 @@
 	  puts ("child: *p != 0");
 	  return 1;
 	}
-
+/* POSIX:
+Attempting to unlock the mutex if it was not locked by the calling thread results in undefined behavior. 
+*/
       if (pthread_mutex_unlock (m) != 0)
 	{
 	  puts ("child: 1st mutex_unlock failed");
diff -Nur libc-ori/nptl/tst-rwlock4.c libc-new/nptl/tst-rwlock4.c
--- libc-ori/nptl/tst-rwlock4.c	2004-03-25 10:34:47.788740568 +0100
+++ libc-new/nptl/tst-rwlock4.c	2004-03-25 10:40:39.772230944 +0100
@@ -17,6 +17,8 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+/* This is a test for behavior not guaranteed by POSIX.  */
+
 #include <errno.h>
 #include <pthread.h>
 #include <stdint.h>
@@ -165,6 +167,9 @@
 	  return 1;
 	}
 
+/* POSIX:
+Results are undefined if the read-write lock rwlock is not held by the calling thread.
+*/
       if (pthread_rwlock_unlock (r) != 0)
 	{
 	  puts ("child: 1st rwlock_unlock failed");

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]