diff options
author | johannst <johannes.stoelp@gmail.com> | 2020-10-05 23:03:15 +0200 |
---|---|---|
committer | johannst <johannes.stoelp@gmail.com> | 2020-10-05 23:03:15 +0200 |
commit | acd4bcbc40cc79096626dcdf6a75d318ad129dd2 (patch) | |
tree | 31e009d11828752514d8a7fc3065a4dfb11fae3f /README.md | |
parent | 2c4330e7c01cf404406dd3380e64304460b29b02 (diff) | |
download | matcha-threads-acd4bcbc40cc79096626dcdf6a75d318ad129dd2.tar.gz matcha-threads-acd4bcbc40cc79096626dcdf6a75d318ad129dd2.zip |
added example to README
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -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. |