From ff052ec5a248a6c56baeecd223b63fdd53d92937 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 3 Oct 2023 22:56:09 +0200 Subject: [PATCH] Library/Application: switch Microbenchmark + SyncBarrier tests ...these were already written envisionaging he new API, so it's more or less a drop-in replacement. - cant use vector anymore, since thread objects are move-only - use ScopedCollection instead, which also has the benefit of allocating the requires space up-front. Allow to deduce the type parameter of the placed elements --- src/lib/scoped-collection.hpp | 2 +- src/lib/test/microbenchmark.hpp | 22 ++++++++----------- .../library/sync-barrier-performance-test.cpp | 4 ++-- tests/library/sync-barrier-test.cpp | 13 +++++------ tests/library/thread-wrapper-test.cpp | 2 +- wiki/thinkPad.ichthyo.mm | 8 +++---- 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/lib/scoped-collection.hpp b/src/lib/scoped-collection.hpp index a6eae5b58..a6e04858a 100644 --- a/src/lib/scoped-collection.hpp +++ b/src/lib/scoped-collection.hpp @@ -309,7 +309,7 @@ namespace lib { * push new entry at the end of this container * and build object of type TY in place there */ - template + template TY& emplace (ARGS&& ...args) { diff --git a/src/lib/test/microbenchmark.hpp b/src/lib/test/microbenchmark.hpp index 9eef66f77..6d16d5e9c 100644 --- a/src/lib/test/microbenchmark.hpp +++ b/src/lib/test/microbenchmark.hpp @@ -55,12 +55,11 @@ #include "lib/meta/function.hpp" -//#include "vault/thread-wrapper.hpp" /////////////////////////////////////////////OOO wieder ThreadJoinable verwenden -#include "lib/sync-barrier.hpp" ///TODO -#include ///TODO +#include "lib/scoped-collection.hpp" +#include "lib/sync-barrier.hpp" +#include "lib/thread.hpp" #include -#include @@ -161,20 +160,18 @@ namespace test{ ASSERT_VALID_SIGNATURE (decltype(subject), size_t(size_t)); struct Thread -// : ThreadJoinable - : std::thread + : lib::ThreadJoinable<> { Thread(FUN const& testSubject, size_t loopCnt, SyncBarrier& testStart) -// : ThreadJoinable("Micro-Benchmark" ///////////////////////////////////////////////////////////OOO wieder Lumiera Thread-Wrapper verwenden #1279 - : std::thread( - [=, &testStart]() // local copy of the test-subject-Functor + : ThreadJoinable{"Micro-Benchmark" + ,[=, &testStart]() // local copy of the test-subject-Functor { testStart.sync(); // block until all threads are ready auto start = system_clock::now(); for (size_t i=0; i < loopCnt; ++i) checksum += testSubject(i); duration = system_clock::now () - start; - }) + }} { } // Note: barrier at begin and join at end both ensure data synchronisation Dur duration{}; // measured time within thread @@ -182,10 +179,9 @@ namespace test{ }; SyncBarrier testStart{nThreads + 1}; // coordinated start of timing measurement - std::vector threads; - threads.reserve(nThreads); + lib::ScopedCollection threads(nThreads); for (size_t n=0; n(); double time_sleepWait_2 = performanceTest(); - cout<<"\n___Microbenchmark_______" + cout<<"\n___Microbenchmark_______ (µs)" <<"\nemptySetup : "< -#include #include #include using test::Test; -using util::and_all; using lib::explore; using std::array; @@ -66,11 +64,12 @@ namespace test { * - book in the compound sum plus a further random number */ class TestThread - : std::thread ////////////////////////////////////////////////////////////////////OOO TOD-oh + : public lib::Thread { public: TestThread() - : thread{[&]() + : Thread{"Load Test" + ,[&]() { //-STAGE-1------------------------------ localSum = rand() % 1000; // generate local value stage1.fetch_add (localSum); // book in local value @@ -83,12 +82,10 @@ namespace test { afterThread.sync(); // wait for other threads and supervisor finish.fetch_add(1); // mark completion of this thread - thread::detach(); //////////////////////////////////////////////OOO Wech-oh }} { } uint localSum; // *deliberately* not initialised to avoid race - bool isRunning() const { return thread::joinable(); } ///////////////////////OOO Wack-oh }; @@ -123,7 +120,7 @@ namespace test { array threads; CHECK (0 == finish); - CHECK (and_all (threads, [](auto& t){ return t.isRunning(); })); + CHECK (explore(threads).and_all()); afterThread.sync(); sleep_for (5ms); // give the threads a chance to terminate diff --git a/tests/library/thread-wrapper-test.cpp b/tests/library/thread-wrapper-test.cpp index 8eb8088ae..9ac7ccae8 100644 --- a/tests/library/thread-wrapper-test.cpp +++ b/tests/library/thread-wrapper-test.cpp @@ -124,7 +124,7 @@ namespace test{ { uint x = rand() % 1000; globalSum += (i + x); - threads.emplace (&TestThread::doIt, i, x); + threads.emplace (&TestThread::doIt, i, x); } // Note: bind to member function, copying arguments while (explore(threads).has_any()) diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index a78cfcc72..363187938 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -80549,7 +80549,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -80880,12 +80880,12 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + - - -