about summary refs log tree commit diff
path: root/sysdeps/generic/libc-start.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-02-14 23:31:11 +0000
committerUlrich Drepper <drepper@redhat.com>2003-02-14 23:31:11 +0000
commit472022708ee08ac559dde540891eb2f8c2a9afcf (patch)
treef30a25b8039eab48c7b6e2737a5f856bdb853b78 /sysdeps/generic/libc-start.c
parente320ef46a7283517aeba1decc20ffb38ed131281 (diff)
downloadglibc-472022708ee08ac559dde540891eb2f8c2a9afcf.tar.gz
glibc-472022708ee08ac559dde540891eb2f8c2a9afcf.tar.xz
glibc-472022708ee08ac559dde540891eb2f8c2a9afcf.zip
Update.
2003-02-14  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/generic/libc-start.c [HAVE_PTR_NTHREADS]: Decrement thread
	counter and only call __exit_thread if this is not the last thread.
Diffstat (limited to 'sysdeps/generic/libc-start.c')
-rw-r--r--sysdeps/generic/libc-start.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/sysdeps/generic/libc-start.c b/sysdeps/generic/libc-start.c
index b4c29dd3c8..a6dbebe123 100644
--- a/sysdeps/generic/libc-start.c
+++ b/sysdeps/generic/libc-start.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1998,1999,2000,2001,2002,2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -38,6 +38,11 @@ extern void __pthread_initialize_minimal (void)
      ;
 #endif
 
+#ifdef HAVE_PTR_NTHREADS
+/* We need atomic operations.  */
+# include <atomic.h>
+#endif
+
 
 extern int BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
 				       int argc,
@@ -148,8 +153,24 @@ BP_SYM (__libc_start_main) (int (*main) (int, char **, char **),
     }
 #ifdef HAVE_CANCELBUF
   else
-    /* Not much left to do but to exit the thread, not the process.  */
-    __exit_thread (0);
+    {
+# ifdef HAVE_PTR_NTHREADS
+      /* One less thread.  Decrement the counter.  If it is zero we
+	 terminate the entire process.  */
+      result = 0;
+      int *const ptr;
+#  ifdef SHARED
+      ptr = __libc_pthread_functions.ptr_nthreads;
+#  else
+      extern int __nptl_nthreads __attribute ((weak));
+      ptr = &__nptl_nthreads;
+#  endif
+
+      if (! atomic_decrement_and_test (ptr))
+# endif
+	/* Not much left to do but to exit the thread, not the process.  */
+	__exit_thread (0);
+    }
 #endif
 
   exit (result);