aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2020-10-05 23:03:15 +0200
committerjohannst <johannes.stoelp@gmail.com>2020-10-05 23:03:15 +0200
commitacd4bcbc40cc79096626dcdf6a75d318ad129dd2 (patch)
tree31e009d11828752514d8a7fc3065a4dfb11fae3f
parent2c4330e7c01cf404406dd3380e64304460b29b02 (diff)
downloadmatcha-threads-acd4bcbc40cc79096626dcdf6a75d318ad129dd2.tar.gz
matcha-threads-acd4bcbc40cc79096626dcdf6a75d318ad129dd2.zip
added example to README
-rw-r--r--README.md39
1 files changed, 39 insertions, 0 deletions
diff --git a/README.md b/README.md
index f4702ac..39642d9 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,45 @@ Supported platforms are `Linux` running on
- `x86_64`
- `arm64`
+### Example
+
+```cpp
+// file: demo.cc
+#include "lib/executor.h"
+#include "lib/thread.h"
+#include <cstdio>
+
+struct MyThread : public nMatcha::Thread {
+ virtual void threadFn() override {
+ puts("like");
+ yield();
+ puts("tea");
+ }
+};
+
+int main() {
+ nMatcha::Executor e;
+ e.spawn(std::make_unique<MyThread>());
+ e.spawn(nMatcha::FnThread::make([](nMatcha::Yielder& y) {
+ puts("I");
+ y.yield();
+ puts("green");
+ }));
+ e.run();
+ return 0;
+}
+```
+
+This example `demo.cc` can be run as
+```bash
+> make -C lib && g++ -o demo demo.cc -I. lib/libmatcha.a && ./demo
+...
+I
+like
+green
+tea
+```
+
### Setup development environment
This project provides a [`Dockerfile`](docker/Dockerfile) with all the required
tools pre-installed.