在 pthread 库中有函数:
pthread_t pthread_self(void);
它返回一个 pthread_t 类型的变量,指代的是调用 pthread_self 函数的线程的 “ID”。...int *)arg));
while (1) {
write(1, msg, strlen(msg));
sleep(1);
}
}
int main() {
int th1 = 1;
pthread_t...tid1;
pthread_create(&tid1, NULL, start_routine, &th1);
int th2 = 2;
pthread_t tid2;
pthread_create...tid = pthread_self();
printf("main: pid=%d, tid=%lu\n", pid, tid);
int th1 = 1;
pthread_t tid1;...pthread_create(&tid1, NULL, start_routine, &th1);
int th2 = 2;
pthread_t tid2;
pthread_create(&tid2