[352] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

Re: Fix to init pthreads earlier in C++

daemon@ATHENA.MIT.EDU (Ken Raeburn)
Sun Jul 7 00:20:23 1996

To: Rob Browning <osiris@cs.utexas.edu>
Cc: pthreads@MIT.EDU
From: Ken Raeburn <raeburn@raeburn.org>
Date: 06 Jul 1996 23:52:28 -0400
In-Reply-To: Rob Browning's message of 05 Jul 1996 13:21:40 -0500

Rob Browning <osiris@cs.utexas.edu> writes:

> Then add this bit to the end of include/pthread.h (just before the
> final #endif):

It is safe to call pthread_init multiple times.  How about this:

	struct __pthread_init {
	  inline __pthread_init() {
	    if (pthread_initial == 0)
	      pthread_init ();
	  }
	};
	static __pthread_init __pthread_init_this_file;

or even:

	  inline __pthread_init() { pthread_init (); }

Either should be reasonably fast, adding only a few instructions and
one function call (and a few bytes of unused data) to each C++ object
file.

Since pthread_initial is set by pthread_init and never set again, it
should be safe to test.  Testing pthread_initial adds a little code
and run time, but saves a little run time too in all but one instance,
since the function call doesn't need to be made.  Whether it's an
overall savings or not is probably platform-dependent, but it probably
wouldn't be a huge difference either way.

home help back first fref pref prev next nref lref last post