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:
parent
01839d4e48
commit
7ef1bab914
1 changed files with 12 additions and 5 deletions
|
|
@ -39,9 +39,11 @@ namespace backend {
|
||||||
|
|
||||||
namespace { // private test classes and data...
|
namespace { // private test classes and data...
|
||||||
|
|
||||||
ulong sum;
|
volatile ulong sum;
|
||||||
ulong checksum;
|
ulong checksum;
|
||||||
|
|
||||||
|
Sync<NonrecursiveLock_NoWait> lockme;
|
||||||
|
|
||||||
const uint NUM_THREADS = 20;
|
const uint NUM_THREADS = 20;
|
||||||
const uint MAX_RAND_SUMMAND = 100;
|
const uint MAX_RAND_SUMMAND = 100;
|
||||||
|
|
||||||
|
|
@ -55,8 +57,8 @@ namespace backend {
|
||||||
|
|
||||||
|
|
||||||
struct TestThread
|
struct TestThread
|
||||||
: Thread
|
: Sync<NonrecursiveLock_NoWait> // using dedicated locking for this test TODO: needs classlock
|
||||||
, Sync<NonrecursiveLock_NoWait> // using dedicated locking for this test
|
, Thread
|
||||||
{
|
{
|
||||||
TestThread()
|
TestThread()
|
||||||
: Thread("test Thread creation",
|
: Thread("test Thread creation",
|
||||||
|
|
@ -67,8 +69,13 @@ namespace backend {
|
||||||
void
|
void
|
||||||
theOperation (uint a, uint b) ///< the actual operation running in a separate thread
|
theOperation (uint a, uint b) ///< the actual operation running in a separate thread
|
||||||
{
|
{
|
||||||
Lock(this);
|
//Lock(this); << broken we need a classlock, using sync-classlock is left as excercise for the reader
|
||||||
sum += (a+b);
|
Sync<NonrecursiveLock_NoWait>::Lock gotit(&lockme);
|
||||||
|
sum *= 2;
|
||||||
|
usleep (200); // force preemption
|
||||||
|
sum += (2*(a+b));
|
||||||
|
usleep (200);
|
||||||
|
sum /= 2;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue