30 using std::atomic_uint;
31 using std::this_thread::yield;
32 using std::this_thread::sleep_for;
34 using std::chrono::system_clock;
35 using std::unique_ptr;
42 using CLOCK_SCALE = std::micro;
58 defaultWrapperLifecycle();
59 verifyThreadLifecycleHooks();
60 demonstrateExplicitThreadLifecycle();
68 using Dur = std::chrono::duration<double, CLOCK_SCALE>;
69 using Point = system_clock::time_point;
74 Thread thread(
"lifecycle", [&]{
75 threadStart = system_clock::now();
77 afterCtor = system_clock::now();
80 while (thread) yield();
83 double offset = Dur{threadStart - afterCtor}.count();
96 ThreadHookable thread{ThreadHookable::Launch([]{ sleep_for (5ms); })
97 .atStart([&]{
stage = 1; })
98 .atExit ([&]{
stage = 2; })
99 .threadID(
"hooked thread")};
107 while (thread) yield();
129 using ThreadHookable::ThreadHookable;
131 atomic_uint processVal{23};
137 processVal = haveFun;
142 CHECK (0 == Dummy::checksum());
146 unique_ptr<TestThread> frontEnd;
147 CHECK (not frontEnd);
150 frontEnd.reset (
new TestThread{
151 TestThread::Launch{&TestThread::doIt, 55u}
152 .atExit([&]{ frontEnd.reset(); })
159 CHECK (23 == frontEnd->processVal);
161 CHECK (55 == frontEnd->processVal);
164 CHECK (not frontEnd);
auto explore(IT &&srcSeq)
start building a IterExplorer by suitably wrapping the given iterable source.
Implementation namespace for support and library code.
void verifyThreadLifecycleHooks()
Abstract Base Class for all testcases.
Simplistic test class runner.
Lumiera GTK UI implementation root.
unittest helper code: test dummy objects to track instances.
Convenience front-end to simplify and codify basic thread handling.
A Dummy object for tests.
Extended variant of the standard case, allowing to install callbacks (hook functions) to be invoked d...
void defaultWrapperLifecycle()
A thin convenience wrapper to simplify thread-handling.
void demonstrateExplicitThreadLifecycle()
void detach_thread_from_wrapper()
allow to detach explicitly — independent from thread-function's state.