From b8cc2491d8d2f239df29a6f85ad8b21e0221e8d1 Mon Sep 17 00:00:00 2001 From: johannst Date: Sat, 19 Sep 2020 19:16:39 +0200 Subject: added basic executor --- example/test.cc | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'example') diff --git a/example/test.cc b/example/test.cc index b436708..1a40958 100644 --- a/example/test.cc +++ b/example/test.cc @@ -1,21 +1,30 @@ #include "lib/matcha.h" -#include #include +#include + +struct TestThread : public Thread { + TestThread(const char* name) : Thread(), mName(name) {} -struct Thread1 : public Thread { virtual void threadFn() override { - puts("start threadFn -> yield()"); + printf("[%s] starting up TestThread -> yield()\n", mName); yield(); - puts("return from yield() -> finish threadFn"); + printf("[%s] yield() -> finishing TestThreads\n", mName); } -} gThread1; + + private: + const char* mName; +}; int main() { - puts("start main thread"); + puts("[main] start main thread"); - gThread1.yield_to(); + Executor e; + e.spawn(std::make_unique("Thread1")); + e.spawn(std::make_unique("Thread2")); + e.spawn(std::make_unique("Thread3")); + e.run(); - puts("finish main thread"); + puts("[main] finish main thread"); return 0; } -- cgit v1.2.3