This is the mail archive of the gcc@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]

Re: basic_string::release and thread safety: what about


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


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