[Gc] RE: Thread creation deadlock with libgc

Dick Porter dick@ximian.com
01 Jul 2003 19:37:00 +0100


--=-axZ0OvLdUuYJQJWNAFZl
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2003-06-19 at 00:08, Boehm, Hans wrote:
> I believe the following patch (consisting of a one line deletion) solves the problem.
> But this is subtle enough that additional testing would be very useful.  I will include
> this in 6.2 unless I hear of problems.

Thanks, that fixed the problem I was seeing at the time.  However, I've
started seeing the deadlock again with libgc 6.2 while stress-testing
mono, and I think I've tracked the problem down:

In pthread_support.c the pthread_create wrapper isn't checking the
return value, and is waiting for the new thread's startup semaphore even
if the real pthread_create failed.  Proposed patch attached.

- Dick



--=-axZ0OvLdUuYJQJWNAFZl
Content-Disposition: inline; filename=gc-diff
Content-Type: text/x-patch; name=gc-diff; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

diff -ur gc6.2-orig/pthread_support.c gc6.2/pthread_support.c
--- gc6.2-orig/pthread_support.c	Thu Jun 19 00:10:38 2003
+++ gc6.2/pthread_support.c	Tue Jul  1 18:47:08 2003
@@ -1247,8 +1247,10 @@
     /* This also ensures that we hold onto si until the child is done	*/
     /* with it.  Thus it doesn't matter whether it is otherwise		*/
     /* visible to the collector.					*/
-    while (0 !=3D sem_wait(&(si -> registered))) {
-        if (EINTR !=3D errno) ABORT("sem_wait failed");
+    if (0 =3D=3D result) {
+	while (0 !=3D sem_wait(&(si -> registered))) {
+            if (EINTR !=3D errno) ABORT("sem_wait failed");
+	}
     }
     sem_destroy(&(si -> registered));
 	LOCK();

--=-axZ0OvLdUuYJQJWNAFZl--