summaryrefslogtreecommitdiff
path: root/t.c
diff options
context:
space:
mode:
Diffstat (limited to 't.c')
-rw-r--r--t.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/t.c b/t.c
new file mode 100644
index 0000000..dcc1814
--- /dev/null
+++ b/t.c
@@ -0,0 +1,48 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <thread.h>
+
+Channel *spamchan;
+
+void
+freethread(void *)
+{
+ char *v = nil;
+
+ threadsetname("freethread");
+Loop:
+ recv(spamchan, &v);
+ if(v == nil){
+ print("nothing to free\n");
+ threadexitsall(0);
+ }
+ print("freeing %s\n", v);
+ free(v);
+ goto Loop;
+}
+
+void
+spammer(void*)
+{
+ int i;
+ char *s;
+
+ threadsetname("spammer");
+ for(i = 0; i < 10; ++i){
+ s = smprint("%d", i);
+ send(spamchan, &s);
+ }
+ send(spamchan, nil);
+}
+
+void
+threadmain(int argc, char *argv[])
+{
+ print("acid -l thread %d\n", getpid());
+ threadsetname("main");
+ spamchan = chancreate(sizeof(char*), 0);
+ threadcreate(spammer, nil, 8192);
+ threadcreate(freethread, nil, 8192);
+ yield();
+}