Boost logo

Boost :

Subject: Re: [boost] Boost.Atomic, pushing forward and a little request for help
From: Matthew Chambers (matt.chambers42_at_[hidden])
Date: 2011-08-02 15:33:37


On 8/2/2011 12:28 PM, Phil Endecott wrote:
> The thing that I believe is missing is tests. Do you have any thoughts about that?

I agree some basic thread safety tests are good to at least suggest that things are working as
expected. It's impossible to guarantee it. The effectiveness of such non-deterministic tests depends
on the hardware concurrency of the testing host (and also what other processes it's running). My
basic thread safety testing technique is:

void testThreadSafetyWorker(boost::barrier* testBarrier)
{
     testBarrier->wait(); // wait until all threads have started

     try
     {
         // run tests using shared atomics
     }
     catch (exception& e)
     {
         cerr << "Exception in worker thread: " << e.what() << endl;
     }
     catch (...)
     {
         cerr << "Unhandled exception in worker thread." << endl;
     }
}

void testThreadSafety(const int& testThreadCount)
{
     boost::barrier testBarrier(testThreadCount);
     boost::thread_group testThreadGroup;
     for (int i=0; i < testThreadCount; ++i)
         testThreadGroup.add_thread(new boost::thread(&testThreadSafetyWorker, &testBarrier));
     testThreadGroup.join_all();
}

I try it for 2, 4, 6, 8 threads.

Hope this helps,
-Matt


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk