This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Fw: [patch] Make std::tr1::shared_ptr thread-safe.
Paolo Carlini wrote:
Alexander... Which is the point of writing "broken" two or three times
per hour? Testcases are needed and concrete help too. Immanuel Kant
comes to my mind: ...
Kant aside for a moment ;-)
One possible way to attempt to isolate a case which fails would be to use a
basic_string<> with an allocator A that zeroes the storage before
deallocating it (these are sometimes used for security reasons). Then we
need
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
}
The intermediate function is needed because the non-const op[] will unshare.
The trick is to somehow force thread1 and thread2 to execute at exactly the
same time... one approach that comes to mind is to have two arrays of
strings and run the two threads in opposite directions, "hoping" for them to
meet at the middle and for an assert to fire.