This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: PATCH for thread-safe C++ static local initialization


Jason Merrill wrote:

This is a patch to implement/use the C++ ABI interface for thread-safe
initialization of local statics. The use generates code something like


Yay!

          static <type> guard;
          if (!guard.first_byte) {
	     if (__cxa_guard_acquire (&guard)) {
	       bool flag = false;
	       try {
	         // Do initialization.
	         flag = true; __cxa_guard_release (&guard);
	         // Register variable for destruction at end of program.
	       } catch {
	         if (!flag) __cxa_guard_abort (&guard);
	       }
            }
          }

which is more complex than the old code which just checked the first byte
of the guard function. Seems like this should probably be controlled by a
flag, but which?


-pthread, and it's oh-too-many synonyms?

It seems to me like if you've asked for threaded code, you probably want this level of thread-safety. I suppose the GCC tradition would be to create yet another flag (-fuse-cxa-guard-acquire) and then another configuration switch (--enable-cxa-guard-acquire), but I that we should be trying to help our users by limiting their choices, rather than pretending to help them by expanding them. :-)

How do people feel about extending the gthr interface to either support
recursive mutexes (emulating in the gthr-* file if necessary) or thread_id,
or both?


I vote for both.

--
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]