diff options
Diffstat (limited to 'example')
-rw-r--r-- | example/demo1.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/example/demo1.cc b/example/demo1.cc index 1c910cd..b83c434 100644 --- a/example/demo1.cc +++ b/example/demo1.cc @@ -10,15 +10,21 @@ struct TestThread : public nMatcha::Thread { TestThread(const char* name) : Thread(), mName(name) {} virtual void threadFn() override { - printf("[%s] starting up TestThread -> yield()\n", mName); + printf("[TestThread(%s)] start -> yield\n", mName); yield(); - printf("[%s] yield() -> finishing TestThreads\n", mName); + printf("[TestThread(%s)] yield -> done\n", mName); } private: const char* mName; }; +void freeThreadFn(nMatcha::Yielder& y) { + puts("[freeThreadFn] start -> yield"); + y.yield(); + puts("[freeThreadFn] yield -> done"); +} + int main() { puts("[main] start main thread"); @@ -26,6 +32,15 @@ int main() { e.spawn(std::make_unique<TestThread>("Thread1")); e.spawn(std::make_unique<TestThread>("Thread2")); e.spawn(std::make_unique<TestThread>("Thread3")); + + e.spawn(nMatcha::FnThread::make([](nMatcha::Yielder& y) { + puts("[Lambda Thread] start -> yield"); + y.yield(); + puts("[Lambda Thread] yield -> done"); + })); + + e.spawn(nMatcha::FnThread::make(freeThreadFn)); + e.run(); puts("[main] finish main thread"); |