This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: basic_string::release and thread safety: what about
- To: Joe Buck <jbuck at Synopsys dot COM>
- Subject: Re: basic_string::release and thread safety: what about
- From: Dima Volodin <dvv at dvv dot org>
- Date: Tue, 06 Jul 1999 19:33:52 -0400
- CC: Mark Mitchell <mark at codesourcery dot com>, drepper at cygnus dot com, egcs at egcs dot cygnus dot com
- Organization: Huh?
- References: <199907062132.OAA11521@atrus.synopsys.com>
Joe Buck wrote:
> In any case, the atomic instructions are far, far cheaper than general
> locks. For the x86, it seems that the assembly language instruction
> required is exactly the same for grab as for release, changing the -1 into
> a 1.
>
> For the Sparc code, I'm not sure.
>
> It might be cleaner to write, for all platforms, something like
>
> charT* grab () { if (selfish) return clone ();
> __atomic_increment(ref);
> return data (); }
> void release () { if (__atomic_decrement(ref) == 0) delete this; }
>
> and then define atomic_increment and atomic_decrement as inline
> functions on a processor-specific basis. These functions could then
> be used elsewhere in the library.
This "atomic" operations should also guarantee cache consistency between all
the CPUs in the system, so if you ask me (am I humble or what? :-) I'd rather
go with the approach taken by the SGI folks - have things shared as little as
possible.
Dima