diff --git a/src/lib/result.hpp b/src/lib/result.hpp index 7787d5160..36c0f6636 100644 --- a/src/lib/result.hpp +++ b/src/lib/result.hpp @@ -196,7 +196,7 @@ namespace lib { return *value_; } - template + template TY get() const { diff --git a/src/lib/thread.hpp b/src/lib/thread.hpp index 9c7ef8f9c..e4a8cf436 100644 --- a/src/lib/thread.hpp +++ b/src/lib/thread.hpp @@ -160,7 +160,7 @@ namespace lib { , threadImpl_{forward (args)... } { } - /** determine if the currently executing code runs within this thread */ + /** detect if the currently executing code runs within this thread */ bool invokedWithinThread() const; void markThreadStart(); @@ -294,6 +294,9 @@ namespace lib { return Policy::isLive(); } + /** @return does this call happen from within this thread? */ + using Policy::invokedWithinThread; + /** Create a new thread to execute the given operation. * The new thread starts up synchronously, can't be cancelled and it can't be joined. diff --git a/tests/library/thread-wrapper-self-recognition-test.cpp b/tests/library/thread-wrapper-self-recognition-test.cpp index e8c578b49..a24f51c54 100644 --- a/tests/library/thread-wrapper-self-recognition-test.cpp +++ b/tests/library/thread-wrapper-self-recognition-test.cpp @@ -26,10 +26,7 @@ #include "lib/test/run.hpp" -#include "lib/test/test-helper.hpp" - #include "lib/thread.hpp" -#include "lib/error.hpp" using test::Test; @@ -38,35 +35,12 @@ using test::Test; namespace lib { namespace test { - namespace { - - class TestThread - : Thread - { - public: - TestThread() - : Thread{"test Thread self recognition" - ,[&]() - { - CHECK (invocation_happens_within_this_thread()); - }} - { } - - bool - invocation_happens_within_this_thread() - { - return invokedWithinThread(); - } - }; - - } - /******************************************************//** * @test verify the ability of a thread to detect code * executing within the thread itself. - * * @see Thread::invokedWithinThread() + * @see thread::ThreadWrapper::invokedWithinThread() * @see steam::control::DispatcherLoop::stateIsSynched() */ class ThreadWrapperSelfRecognitionTest_test : public Test @@ -75,11 +49,13 @@ namespace test { virtual void run (Arg) { - TestThread testThread; + ThreadJoinable testThread{"Thread self detection" + ,[&]{ + return testThread.invokedWithinThread(); + }}; - CHECK (not testThread.invocation_happens_within_this_thread()); - - usleep(10); // give the thread a chance to run before shutdown + CHECK (not testThread.invokedWithinThread()); + CHECK (testThread.join().get()); } }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 5538263d1..57cb5956e 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -79016,7 +79016,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -79268,7 +79268,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -79954,7 +79954,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -80020,7 +80020,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -80040,8 +80040,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + @@ -80060,6 +80060,34 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + + + + + + +

+ ...das ist interessant, aber nicht kritisch; und zwar weil ich den Test jetzt umgeschrieben habe auf ein Lambda, und gar keine eigenständige Klasse mehr verwende — viel spannender ist, daß der C++ - Compiler überhaupt schafft, solchen Code zu „knacken“ +

+ + +
+
+ + +