forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.1.c
39 lines (30 loc) · 660 Bytes
/
11.1.c
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
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
pthread_t ntid;
void printids(const char *s)
{
pid_t pid;
pthread_t tid;
pid = getpid();
tid =-pthread_self();
printf("%s pid %u tid %u (0x%x)\n", s, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid);
}
void *thr_fn(void *arg)
{
printids("new thread: ");
return ((void *)0);
}
int main(void)
{
int err;
err = pthread_create(&ntid, NULL, thr_fn, NULL);
if (0 != err) {
printf("can't create thread :%s\n", strerror(err));
exit(-1);
}
printids("main thread: ");
sleep(1);
return 0;
}