This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: Fw: [patch] Make std::tr1::shared_ptr thread-safe.


On Apr 3, 2005 6:58 PM, Peter Dimov <pdimov@mmltd.net> wrote:
> Peter Dimov wrote:
> > basic_string<char, ..., A> s1( "string" );
> > basic_string<char, ..., A> s2( s1 );
> >
> > inline void f( basic_string<char, ..., A> const & s )
> > {
> >    assert( s[0] == 's' );
> > }
> >
> > void thread1()
> > {
> >    f( s1 );
> >    // destroy s1
> > }
> >
> > void thread2()
> > {
> >    f( s2 );
> >    // destroy s2
> > }
> 
> Per Alexander's suggestion:
> 
> inline char front( basic_string<char, ..., A> const & s )
> {
>    return s[0];
> }
> 
> void thread1()
> {
>   char c1 = front( s1 );
>   // destroy s1
>   assert( c1 == 's' );
> }
> 
> void thread2()
> {
>   char c2 = front( s2 );
>   // destroy s2
>   assert( c2 == 's' );
> }
> 
> is likely to "fail faster".

"Fail fastest" would be to read a few chars (without any branching in 
between) from different cache lines and shred the string (in its dtor) 
in the opposite direction after mere check (not relatively slow atomic 
read-modify-write with branching preceding destruction). I mean some
std::string ref-counting scheme along the lines of (note that that 
sketch has the same problem with respect to insufficient msync) 
<http://www.google.de/groups?selm=3DE3A142.7DAACB3B%40web.de>.

regards,
alexander.


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