39 using std::atomic_uint;
40 using std::this_thread::yield;
41 using std::this_thread::sleep_for;
43 using std::chrono::system_clock;
44 using std::unique_ptr;
51 using CLOCK_SCALE = std::micro;
67 defaultWrapperLifecycle();
68 verifyThreadLifecycleHooks();
69 demonstrateExplicitThreadLifecycle();
77 using Dur = std::chrono::duration<double, CLOCK_SCALE>;
78 using Point = system_clock::time_point;
83 Thread thread(
"lifecycle", [&]{
84 threadStart = system_clock::now();
86 afterCtor = system_clock::now();
89 while (thread) yield();
92 double offset = Dur{threadStart - afterCtor}.count();
104 atomic_uint
stage{0};
105 ThreadHookable thread{ThreadHookable::Launch([]{ sleep_for (5ms); })
106 .atStart([&]{
stage = 1; })
107 .atExit ([&]{
stage = 2; })
108 .threadID(
"hooked thread")};
116 while (thread) yield();
138 using ThreadHookable::ThreadHookable;
140 atomic_uint processVal{23};
146 processVal = haveFun;
151 CHECK (0 == Dummy::checksum());
155 unique_ptr<TestThread> frontEnd;
156 CHECK (not frontEnd);
159 frontEnd.reset (
new TestThread{
160 TestThread::Launch{&TestThread::doIt, 55u}
161 .atExit([&]{ frontEnd.reset(); })
168 CHECK (23 == frontEnd->processVal);
170 CHECK (55 == frontEnd->processVal);
173 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.
unittest helper code: test dummy objects to track instances.
void verifyThreadLifecycleHooks()
Abstract Base Class for all testcases.
Simple test class runner.
Lumiera GTK UI implementation root.
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.