Notes from the meeting

Christophe de Dinechin ddd at cup.hp.com
Thu Jul 6 22:01:48 UTC 2000


Jim Dehnert wrote:
> 
> Also, on Alex's request, we revisited the issue of thread-safe one-time
> initialization.  We agreed that, if there's to be any hope of
> interoperability of compilers supporting it, they need the same API for
> handling the guard variable.
> 
> The proposed solution is to strongly suggest that implementors who
> hope ever to support this call a routine:
> 
>         extern "C" int __cxx_gv_test_and_set ( long long *gv );
> 
> The routine returns "true" to only one caller, and "false" to all
> others after the first has released the lock.  We neglected to note
> that the release also needs specification.  How about:
> 
>         extern "C" void __cxx_gv_release ( long long *gv );
> 

The current HP implementation does not use a release, and has a more specialized
routine. This would be something like:

	extern "C" void __cxa_allocate_static(
		bool *flag,
		void *object_address,
		void (*object_dtor)(void *object));

The calling sequence for:

	static X x

becomes:

	static bool static_x_flag;
	static X x;
	if (!static_x_flag)
		__cxa_allocate_static(&static_x_flag,
				      &x, __addressof(X::~X));

This has the following benefits:

1/ If the static has been initialized already, the flag is set, so we
short-circuit the function call

2/ The function registers the object and its destructor for invokation at exit()
time.


The function itself deals with the flag in a thread-safe way, but this requires
only one mutex inside the function. This is important, since test and set
operations are potentially costly memorywise on IA64 (they are definitely on
PA-RISC, where any mutex / lock / whatever must be 16-bytes aligned)


Regards
Christophe




More information about the cxx-abi-dev mailing list