From 9376bff71ef0476fdaed87c0fed728b7c8dfd547 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 28 Sep 2009 17:54:50 +0200 Subject: [PATCH] race fixed, test pass --- src/backend/thread-wrapper.hpp | 8 +++----- tests/40components.tests | 2 +- tests/lib/typed-counter-test.cpp | 34 +++++++++++++------------------- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/backend/thread-wrapper.hpp b/src/backend/thread-wrapper.hpp index 23c553724..730b4338b 100644 --- a/src/backend/thread-wrapper.hpp +++ b/src/backend/thread-wrapper.hpp @@ -62,12 +62,11 @@ namespace backend { * wait state, the contained mutex remains locked and prevents the thread * manager from invoking the broadcast() on the condition var. * - * @note this is a draft. It doesn't even work, because Cehteh is still planning - * details of the thread handling and didn't implement the waiting feature. + * @see thread-wrapper-join-test.cpp */ class JoinHandle : public Sync - , Sync::Lock + , Sync::Lock // noncopyable, immediately acquire the lock { typedef Sync SyncBase; @@ -95,8 +94,7 @@ namespace backend { isWaiting_ = true; return false; // causes entering the blocking wait } - TODO ("any possibility to detect spurious wakeups? can they happen?"); - return true; // causes end of the blocking wait + return true; // causes end of blocking wait } diff --git a/tests/40components.tests b/tests/40components.tests index 63db0fb3a..c7efedcf3 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -848,7 +848,7 @@ return: 0 END -PLANNED "building type based contexts" TypedCounter_test < - ** This test builds several "families", which each share a TypedCounter. Each of these + ** This test builds several "families", each sharing a TypedCounter. Each of these ** families runs a set of member threads, which concurrently access the TypedCounter of ** this family. After waiting for all threads to finish, we compare the checksum built ** within the target objects with the checksum collected through the TypedCounters. @@ -62,8 +62,9 @@ namespace test{ using backend::JoinHandle; using util::for_each; using util::isnil; - using std::tr1::bind; using std::tr1::placeholders::_1; + using std::tr1::bind; + using std::tr1::ref; using std::vector; using std::rand; @@ -71,8 +72,8 @@ namespace test{ namespace { // test data and helpers... const uint MAX_FAMILIES = 20; ///< maximum separate "families", each sharing a TypedCounter - const uint MAX_MEMBERS = 5; ///< maximum members per family (member == test thread) - const uint MAX_ITERATIONS = 5; ///< maximum iterations within a single test thread + const uint MAX_MEMBERS = 30; ///< maximum members per family (member == test thread) + const uint MAX_ITERATIONS = 50; ///< maximum iterations within a single test thread const uint MAX_DELAY_ms = 3; ///< maximum delay between check iterations @@ -225,30 +226,27 @@ namespace test{ : JoinHandle, Thread { - TypedCounter& counterSet_; - long localChecksum_; - public: SingleCheck (TypedCounter& counter_to_use) - : Thread("TypedCounter_test worker Thread", - bind (&SingleCheck::runCheckSequence, this, (rand() % MAX_ITERATIONS)), - (backend::JoinHandle&)*this + : Thread("TypedCounter_test worker Thread" + , bind (&SingleCheck::runCheckSequence, this, ref(counter_to_use), (rand() % MAX_ITERATIONS)) + , (backend::JoinHandle&)*this ) - , counterSet_(counter_to_use) - , localChecksum_(0) { } ~SingleCheck () { this->join(); } private: - void runCheckSequence(uint iterations) + void runCheckSequence(TypedCounter& counter, uint iterations) { - while (--iterations) + do { usleep (1000 * (rand() % MAX_DELAY_ms)); - targetCollection.torture (counterSet_); - } } + targetCollection.torture (counter); + } + while (iterations--); + } }; @@ -297,10 +295,6 @@ namespace test{ * in each of them concurrently. Check the proper allocation of type-IDs in each * context and verify correct counting operation by checksum. * - * @todo using currently (9/09) a simple implementation based on static variables. - * This causes waste of storage for the type-based tables. It would be better - * if each set would build it's own Type-IDs. Ticket # - * * @see TypedAllocationManager * @see typed-counter.hpp */