summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-08-08 23:56:57 +0000
committerrodri <rgl@antares-labs.eu>2023-08-08 23:56:57 +0000
commit5a0e28438fe4c0f8cc55430c388c2016cc185cbf (patch)
treed8b27049f77f84999871231fea525c38ed371cec
parent738f91837bffa7e3ff9ac9323dd91cf9453cde77 (diff)
downloadbrokentoys-5a0e28438fe4c0f8cc55430c388c2016cc185cbf.tar.gz
brokentoys-5a0e28438fe4c0f8cc55430c388c2016cc185cbf.tar.bz2
brokentoys-5a0e28438fe4c0f8cc55430c388c2016cc185cbf.zip
alt channel send test.
-rw-r--r--chansend.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/chansend.c b/chansend.c
new file mode 100644
index 0000000..445db42
--- /dev/null
+++ b/chansend.c
@@ -0,0 +1,40 @@
+#include <u.h>
+#include <libc.h>
+#include <thread.h>
+
+void
+recvthread(void *arg)
+{
+ Channel *c = arg;
+ int n;
+
+ while(recv(c, &n) > 0)
+ fprint(2, "got %x\n", n);
+}
+
+void
+threadmain()
+{
+ Channel *c;
+ Alt a[2];
+ int n;
+
+ c = chancreate(sizeof(int), 1);
+ n = 0xB00B5;
+
+ a[0].op = CHANSND;
+ a[0].c = c;
+ a[0].v = &n;
+ a[1].op = CHANEND;
+
+ threadcreate(recvthread, c, mainstacksize);
+
+ for(;;)
+ switch(alt(a)){
+ case -1:
+ return;
+ case 0:
+ fprint(2, "sent %x\n", n);
+ break;
+ }
+}