aboutsummaryrefslogtreecommitdiff
path: root/example/test.cc
diff options
context:
space:
mode:
authorjohannst <johannes.stoelp@gmail.com>2020-09-17 00:06:28 +0200
committerjohannst <johannes.stoelp@gmail.com>2020-09-17 00:06:28 +0200
commitdfa05a97e083122a788c0ffb5c9e26888fe3dcd1 (patch)
tree7655b3c4ff7ff5bda43a6a26bcbb406e9bf2999f /example/test.cc
parent4e784fc5668909789fa90b8448116b096130740f (diff)
downloadmatcha-threads-dfa05a97e083122a788c0ffb5c9e26888fe3dcd1.tar.gz
matcha-threads-dfa05a97e083122a788c0ffb5c9e26888fe3dcd1.zip
setup new stack + basic yielding between two stacks
Diffstat (limited to 'example/test.cc')
-rw-r--r--example/test.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/example/test.cc b/example/test.cc
new file mode 100644
index 0000000..7307bec
--- /dev/null
+++ b/example/test.cc
@@ -0,0 +1,33 @@
+#include "lib/matcha.h"
+
+#include <cassert>
+#include <cstdio>
+
+Thread* gThread1 = nullptr;
+
+void thread1_1() {
+ puts("thread1_1");
+}
+
+void thread1() {
+ puts("start thread1");
+ thread1_1();
+ puts("finish thread1");
+
+ assert(gThread1 != nullptr);
+ yield_from(*gThread1);
+}
+
+int main() {
+ puts("start main thread");
+
+ Thread t(thread1);
+ gThread1 = &t;
+
+ yield_to(t);
+
+ gThread1 = nullptr;
+
+ puts("finish main thread");
+ return 0;
+}