23,120
社区成员
发帖
与我相关
我的任务
分享
1 #include "apue.h"
2 #include <pthread.h>
3
4 pthread_t ntid;
5
6 void
7 printids(const char *s)
8 {
9 pid_t pid;
10 pthread_t tid;
11
12 pid = getpid();
13 tid = pthread_self();
14 printf("%s pid %u tid %u (0x%x)\n", s, (unsigned int)pid,
15 (unsigned int)tid, (unsigned int)tid);
16 }
17
18 void *
19 thr_fn(void *arg)
20 {
21 printids("new thread: ");
22 return((void *)0);
23 }
24
25 int
26 main(void)
27 {
28 int err;
29
30 err = pthread_create(&ntid, NULL, thr_fn, NULL);
31 if (err != 0)
32 err_quit("can't create thread: %s\n", strerror(err));
33 printids("main thread:");
34 sleep(1);
35 exit(0);
36 }