summaryrefslogtreecommitdiff
path: root/t.c
blob: dcc1814c4f267e559b35895e14c1efab40516559 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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();
}