热门

最新

红包

立Flag

投票

同城

我的

发布
he_zhidan
软件架构师何志丹 《深入浅出Visual c++》书籍作者
3 年前
truehe_zhidan

请通过博客而不是最新回访。前者优先访问置顶博客,后者优先访问最新动态博客

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
#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;}这孩子天赋异禀,但是被父母打了一顿~
立即登录