blob: 710a33d719bec6da401ee410c447417194ddfa74 (
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
|
#include "a.h"
typedef struct New New;
struct New
{
void (*fn)(void*);
void *arg;
};
Channel *mailthreadchan;
void
mailthread(void (*fn)(void*), void *arg)
{
New n;
n.fn = fn;
n.arg = arg;
send(mailthreadchan, &n);
}
void
mailproc(void *v)
{
New n;
while(recv(mailthreadchan, &n) == 1)
threadcreate(n.fn, n.arg, STACK);
}
void
mailthreadinit(void)
{
mailthreadchan = chancreate(sizeof(New), 0);
proccreate(mailproc, nil, STACK);
}
|