premature fix for the threadwrapper test

Added some more fuzz and sleeping to the test calculation to have a actual
chance to fail when something is not well locked.

Using a premature classlock, locking instances was insufficient.
This commit is contained in:
Christian Thaeter 2010-02-03 10:45:58 +01:00
parent 01839d4e48
commit 7ef1bab914

View file

@ -39,9 +39,11 @@ namespace backend {
namespace { // private test classes and data...
ulong sum;
volatile ulong sum;
ulong checksum;
Sync<NonrecursiveLock_NoWait> lockme;
const uint NUM_THREADS = 20;
const uint MAX_RAND_SUMMAND = 100;
@ -55,8 +57,8 @@ namespace backend {
struct TestThread
: Thread
, Sync<NonrecursiveLock_NoWait> // using dedicated locking for this test
: Sync<NonrecursiveLock_NoWait> // using dedicated locking for this test TODO: needs classlock
, Thread
{
TestThread()
: Thread("test Thread creation",
@ -67,8 +69,13 @@ namespace backend {
void
theOperation (uint a, uint b) ///< the actual operation running in a separate thread
{
Lock(this);
sum += (a+b);
//Lock(this); << broken we need a classlock, using sync-classlock is left as excercise for the reader
Sync<NonrecursiveLock_NoWait>::Lock gotit(&lockme);
sum *= 2;
usleep (200); // force preemption
sum += (2*(a+b));
usleep (200);
sum /= 2;
}
};