diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-09-19 19:16:39 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-09-19 19:39:01 +0200 |
commit | b8cc2491d8d2f239df29a6f85ad8b21e0221e8d1 (patch) | |
tree | b8f1f354586198d78168fc8f6e0905a4cce128cb /example | |
parent | 1f415f839ccdcc0f455d8b4c9adacbf0f60fc89f (diff) | |
download | matcha-threads-b8cc2491d8d2f239df29a6f85ad8b21e0221e8d1.tar.gz matcha-threads-b8cc2491d8d2f239df29a6f85ad8b21e0221e8d1.zip |
added basic executor
Diffstat (limited to 'example')
-rw-r--r-- | example/test.cc | 25 |
1 files changed, 17 insertions, 8 deletions
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 <cassert> #include <cstdio> +#include <memory> + +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<TestThread>("Thread1")); + e.spawn(std::make_unique<TestThread>("Thread2")); + e.spawn(std::make_unique<TestThread>("Thread3")); + e.run(); - puts("finish main thread"); + puts("[main] finish main thread"); return 0; } |