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.


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".


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