From 7ef1bab91437dec0cab7e9b45eb5ec9ca867cd20 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Wed, 3 Feb 2010 10:45:58 +0100 Subject: [PATCH] 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. --- tests/lib/thread-wrapper-test.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/lib/thread-wrapper-test.cpp b/tests/lib/thread-wrapper-test.cpp index b05a7d5c3..6b686b2dd 100644 --- a/tests/lib/thread-wrapper-test.cpp +++ b/tests/lib/thread-wrapper-test.cpp @@ -39,9 +39,11 @@ namespace backend { namespace { // private test classes and data... - ulong sum; + volatile ulong sum; ulong checksum; + Sync lockme; + const uint NUM_THREADS = 20; const uint MAX_RAND_SUMMAND = 100; @@ -55,8 +57,8 @@ namespace backend { struct TestThread - : Thread - , Sync // using dedicated locking for this test + : Sync // 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::Lock gotit(&lockme); + sum *= 2; + usleep (200); // force preemption + sum += (2*(a+b)); + usleep (200); + sum /= 2; } };