[Top][All Lists]

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

Getting libpthread working again

From: Thomas Schwinge
Subject: Getting libpthread working again
Date: Sun, 12 Apr 2009 17:32:12 +0200
User-agent: Mutt/1.5.11


When linking the pthread tests against a libpthread built (with Samuel's
TLS patches) from CVS HEAD (or any of the Viengoos branches, for that
matter) I always get this:

    $ ./test-1
    test-1: ../../HEAD/libpthread/sysdeps/mach/hurd/i386/pt-setup.c:103:
    __pthread_setup: Unexpected error: (ipc/send) invalid destination
    $ ./test-1-static 
    __pthread_setup: Unexpected error: (ipc/send) invalid destination

I tracked this down to the 2008-08-16 __pthread_free_threads change --
apparently nobody ever tried to use the CVS HEAD libpthread since then?
(We absolutely need to come up with better automated testing methods...)
The pthread library was now trying to reuse kernel threads that have been
invalidated before.  I created the attached patch to get that fixed again
(plus the malloc to calloc patch needed for CVS HEAD).  Neal, is this
approach correct?  I have stolen the thread_suspend thing from Viengoos
-- is that correct for Mach as well?  (And the while (1) loop is
superfluous for all variants, isn't it?)  At least, this way all of the
libpthread test suite programs complete to satisfaction, both dynamically
and statically linked.

diff --git a/sysdeps/mach/pt-thread-dealloc.c b/sysdeps/mach/pt-thread-dealloc.c
index 55d8c4d..0c4a4fc 100644
--- a/sysdeps/mach/pt-thread-dealloc.c
+++ b/sysdeps/mach/pt-thread-dealloc.c
@@ -38,4 +38,6 @@ __pthread_thread_dealloc (struct __pthread *thread)
      assert.  */
   __mach_port_destroy (__mach_task_self (),
+  thread->have_kernel_resources = 0;
diff --git a/sysdeps/mach/pt-thread-halt.c b/sysdeps/mach/pt-thread-halt.c
index 973cde1..a9c3858 100644
--- a/sysdeps/mach/pt-thread-halt.c
+++ b/sysdeps/mach/pt-thread-halt.c
@@ -32,6 +32,21 @@
 __pthread_thread_halt (struct __pthread *thread)
-  error_t err = __thread_terminate (thread->kernel_thread);
-  assert_perror (err);
+  if (thread->have_kernel_resources)
+    {
+      if (thread == _pthread_self ())
+       {
+         while (1)
+           {
+             error_t err = __thread_suspend (thread->kernel_thread);
+             assert_perror (err);
+             assert (! "Failed to suspend self.");
+           }
+       }
+      else
+       {
+         error_t err = __thread_terminate (thread->kernel_thread);
+         assert_perror (err);
+       }
+    }


PS: Please, don't install patches into the CVS repositories at the
moment, due to the CVS to git migration.

PPS: While digging through the libpthread code I wondered whether for the
Hurd servers cthreads to pthread migration PTHREAD_THREADS_MAX being
defined to 64 might be too small for some heavily multi-threaded Hurd

PPPS: Happy easter!

Attachment: signature.asc
Description: Digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]