blob: 73b600e7df015762cbe95af5a12dc59acf7a5d1e (
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
|
#include <pthread.h>
#include <utf.h>
#include <fmt.h>
pthread_key_t key;
void
pexit(void *v)
{
int s;
pthread_setspecific(key, (void*)1);
switch(fork()){
case -1:
fprint(2, "fork: %r\n");
case 0:
_exit(0);
default:
wait(&s);
}
pthread_exit(0);
}
int
main(int argc, char *argv[])
{
int i;
pthread_t pid;
pthread_key_create(&key, 0);
for(i=0;; i++){
print("%d\n", i);
if(pthread_create(&pid, 0, pexit, 0) < 0){
fprint(2, "pthread_create: %r\n");
abort();
}
}
}
|