[PATCH] pthread_fork

Thomas Pfaff tpfaff@gmx.net
Thu Aug 15 13:00:00 GMT 2002

This patch will fix the pthread key related problems with fork (key value
is restored after fork) and some minor fork related fixes.


2002-08-15  Thomas Pfaff  <tpfaff@gmx.net>

	* fork.cc (fork_child): fixup_after_fork call changed.
	(fork_parent): Added call to MTinterface->fixup_before_fork to
	save TLS values.
	(fork): Added critical section, fixup_before_fork will use a
	local key buffer that is not thread safe.
	* init.cc (dll_entry): Run pthread_key destructors on thread
	detach or process detach.
	Changed call to store reents.
	* thread.cc: pthread_key_destructor and
	pthread_key_destructor_list class has been removed.
	(_reent_clib): Modified call to get reent value.
	(_reent_winsup): Ditto.
	(MTinterface::Init): Rewritten.
	(MTinterface::init_pthread): New Method.
	(MTinterface::fixup_before_fork): Ditto.
	(MTinterface::fixup_after_fork): Restore key values.
	Initialize thread instance for main thread.
	(MTinterface::run_key_dtors): New method, replaces IterateNull.
	(pthread::self): Allocate a pthread instance if not already done.
	This will give a thread a valid thread self pointer if it was
	created by ServiceMain or CreateThread.
	(pthread::destructor): New method.
	(pthread::exit): IterateNull is now done on thread detach,
	the cleanup in the key destructor function.
	(pthread_key::pthread_key): Is now a list.
	(pthread_key::set): Return error code.
	(pthread_key::get): Protect Win32 LastError.
	(pthread_key::fixup_before_fork): Save actual value in buffer.
	(pthread_key::fixup_after_fork): Restore key value.
	(pthread::thread_init_wrapper): Modified due to key handling
	(__pthread_setspecific): Return error if failed.
	* thread.h (class pthread_key): New members fork_buf and
	New methods fixup_before_fork and fixup_after_fork.
	(class pthread_key_destructor): Removed.
	(class pthread_key_destructor_list): Ditto.
	(pthread::destructor): New method.
	(MTinterface::keys): New member.
	(MTinterface::reent_key): Ditto.
	(MTinterface::thread_self_key): Ditto.
	(MTinterface::fork_lock): Ditto.
	(MTinterface::init_pthread): New method.
	(MTinterface::fixup_before_fork): Ditto.
	(MTinterface::run_key_dtors): Ditto.
	(MTinterface::init_crit_section): Ditto.
	Moved MT_INTERFACE define from thread.cc to thread.h.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pthread_fork.patch
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20020815/f9eb0af0/attachment.ksh>

More information about the Cygwin-patches mailing list