shithub: battleship

Download patch

ref: 97f4b9b97c470501d25ac82cad771bdff75e9b59
parent: 21d0ffbbf001fd209208e33503890ad6847105db
parent: 5a0e28438fe4c0f8cc55430c388c2016cc185cbf
author: rodri <rgl@antares-labs.eu>
date: Sat Jan 6 11:24:51 EST 2024

merged

--- /dev/null
+++ b/chansend.c
@@ -1,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;
+		}
+}