aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2020-10-05 17:57:26 +0200
committerjohannst <johannes.stoelp@gmail.com>2020-10-05 17:57:26 +0200
commit40335c667870e72deb739b81ffbf8d23902ebe71 (patch)
treef98587f320ec85f3d912430454e51e1acf99c04f /example
parente710fae8b8a1c34109644e5991f293b58e7eaa16 (diff)
downloadmatcha-threads-40335c667870e72deb739b81ffbf8d23902ebe71.tar.gz
matcha-threads-40335c667870e72deb739b81ffbf8d23902ebe71.zip
add support for function objects
Diffstat (limited to 'example')
-rw-r--r--example/demo1.cc19
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");