热门

最新

红包

立Flag

投票

同城

我的

发布
m0_73651896
Luyoung0001
3 年前
truem0_73651896

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
int done = 0;
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t c = PTHREAD_COND_INITIALIZER;
void thread_exit() {
pthread_mutex_lock(&m);
done = 1;
pthread_cond_signal(&c);
pthread_mutex_unlock(&m);
}
void *child(void *arg) {
printf("child: hello, world!\n");
thread_exit();
return NULL;
}
void thread_join() {
pthread_mutex_lock(&m);
while (done == 0) {
pthread_cond_wait(&c, &m);
}
pthread_mutex_unlock(&m);
}
int main() {
printf("parent: hello, son!\n");
pthread_t p;
pthread_create(&p, NULL, child, NULL);
thread_join();
printf("parent: wtf?!\n");
return 0;
}

这孩子天赋异禀,但是被父母打了一顿~

码友杂谈区
CSDN App 扫码分享
分享
评论
2
打赏
  • 复制链接
  • 举报
下一条:
我
立即登录