From 39fc0d36aefea70fa97addbeaf1f8e9ac0fa8232 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 22 Feb 2007 12:34:55 +0000 Subject: * dcrt0.cc (child_info_fork::alloc_stack_hard_way): Change sense of guard test. Increase size of stack reserved and increase size before the current stack pointer. Use pointers when doing arithmetic. (dll_crt0_1): Initialize exception handler when we notice we're the child of a fork from non-main thread. * fork.cc (frok::parent): Make argument volatile. (frok::child): Ditto. (lock_signals): New class. (lock_pthread): Ditto. (hold_everhthing): Ditto. (frok::parent): Move atforkprepare and atforkparent to lock_pthread class. (fork): Make ischild boolean. Use hold_everything variable within limited scope to set various mutexes in such a way as to avoid deadlocks. * thread.h (pthread_mutex::tid): New variable, active when debugging for tracking thread id of owner. (pthread_mutex::set_owner): Set tid when debugging. * thread.cc (pthread_mutex::pthread_mutex): Clear tid. (pthread_mutex::_unlock): Ditto when unlocking. (pthread_mutex::fixup_after_fork): Set tid to special value after forking since owner is unknown. --- winsup/cygwin/thread.cc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'winsup/cygwin/thread.cc') diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index fc29fc19a..936d9a55c 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -1,9 +1,7 @@ /* thread.cc: Locking and threading module functions - Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Red Hat, Inc. - - Originally written by Marco Fuykschot - Substantialy enhanced by Robert Collins + Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, + 2006, 2007 Red Hat, Inc. This file is part of Cygwin. @@ -1599,7 +1597,11 @@ pthread_mutex::pthread_mutex (pthread_mutexattr *attr) : verifyable_object (PTHREAD_MUTEX_MAGIC), lock_counter (0), win32_obj_id (NULL), recursion_counter (0), - condwaits (0), owner (NULL), type (PTHREAD_MUTEX_ERRORCHECK), + condwaits (0), owner (NULL), +#ifdef DEBUGGING + tid (0), +#endif + type (PTHREAD_MUTEX_ERRORCHECK), pshared (PTHREAD_PROCESS_PRIVATE) { win32_obj_id = ::CreateSemaphore (&sec_none_nih, 0, LONG_MAX, NULL); @@ -1680,6 +1682,9 @@ pthread_mutex::_unlock (pthread_t self) if (--recursion_counter == 0) { owner = NULL; +#ifdef DEBUGGING + tid = 0; +#endif if (InterlockedDecrement ((long *)&lock_counter)) // Another thread is waiting ::ReleaseSemaphore (win32_obj_id, 1, NULL); @@ -1713,11 +1718,21 @@ pthread_mutex::_fixup_after_fork () api_fatal ("pthread_mutex::_fixup_after_fork () doesn'tunderstand PROCESS_SHARED mutex's"); if (owner == NULL) - /* mutex has no owner, reset to initial */ - lock_counter = 0; + { + /* mutex has no owner, reset to initial */ + lock_counter = 0; +#ifdef DEBUGGING + tid = 0; +#endif + } else if (lock_counter != 0) - /* All waiting threads are gone after a fork */ - lock_counter = 1; + { + /* All waiting threads are gone after a fork */ + lock_counter = 1; +#ifdef DEBUGGING + tid = 0xffffffff; /* Don't know the tid after a fork */ +#endif + } win32_obj_id = ::CreateSemaphore (&sec_none_nih, 0, LONG_MAX, NULL); if (!win32_obj_id) -- cgit v1.2.3