金庸群侠传x女主完美线:thread
来源:百度文库 编辑:九乡新闻网 时间:2024/05/05 08:40:02
#include #include #include #include #include #include #include using namespace std;#define THREAD_NUMBER 2/* 初始化条件变量*/static pthread_cond_t cond= PTHREAD_COND_INITIALIZER;/* 初始化mutex*/static pthread_mutex_t mutex= PTHREAD_MUTEX_INITIALIZER;void* thread1(void *arg){ int ret; pthread_mutex_lock(&mutex); printf("thread1 locked the mutex\n"); printf("thread1 is waiting for condition signal...\n"); cout <<"cond:"< /* 休眠5 秒钟*/ while (now.tv_sec-old.tv_sec< 5) { sleep(1); gettimeofday(&now,NULL); i++; printf("thread2 sleep %d seconds\n", i); } printf("thread1 calls pthread_cond_signal...\n"); /* 启动等待条件变量cond的其他线程*/ ret = pthread_cond_signal(&cond); cout <<"cond:"<<&cond<int main(int argc, char *argv[]){ int i; int ret_val; pthread_mutex_init(&mutex,NULL); pthread_t pt[THREAD_NUMBER]; memset(pt,0,THREAD_NUMBER); ret_val = pthread_create(&pt[0], NULL, thread1, NULL); if (ret_val != 0 ) { printf("pthread_create error!\n"); exit(1); } sleep(1); ret_val = pthread_create(&pt[1], NULL, thread2, NULL); if (ret_val != 0 ) { printf("pthread_create error!\n"); exit(1); }
for (i = 0; i < THREAD_NUMBER; i++) { ret_val = pthread_join(pt[i], NULL); if (ret_val != 0) { printf("pthread_join error!\n"); exit(1); } } pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); return 0;}
for (i = 0; i < THREAD_NUMBER; i++) { ret_val = pthread_join(pt[i], NULL); if (ret_val != 0) { printf("pthread_join error!\n"); exit(1); } } pthread_mutex_destroy(&mutex); pthread_cond_destroy(&cond); return 0;}
thread
Thread
理解 Thread.Sleep 函数
Thread.currentThread().getContextClassLoader().getResourceAsStream
example of join another thread
C#多线程编程之Thread类
Windows XP 中出现错误消息:“STOP 0x000000EA THREAD
Love Is Just a Thread 爱只是一根线
辨析股票投资的误区 原帖:http://www.gupiao168.com/bbs/thread-567393-1-1.html
a bad way simply solve the uncatched exception throw from a thread
白苹果修复手册(http://benyouhui.it168.com/thread-1319954-1-1.html)
通过Java thread dump分析找到耗费CPU最高的源代码
国家竞争力http://wenda.tianya.cn/wenda/thread?tid=4fa065001589a1bf
Windows核心编程(第五版)笔记 第六章 线程基本概念(Thread Basics)
Windows核心编程(第五版)笔记 第九章 利用内核对象同步线程(Thread Sync...
成交量及夹板看盘法在实战中的应用 -原帖:http://www.gupiao168.com/bbs/thread-526133-1-16.html
价值投资与价格“投机”的十大金律 - 原帖:http://www.gupiao168.com/bbs/thread-526173-1-16.html
前辈的驾驶经验和技巧 http://bbs.auto.sina.com.cn/40/105/thread-2067955-1-1.html
Windows核心编程(第五版)笔记 第八章 用户模式下的线程同步(Thread Sync...
擅做熊市悟出1144公式14年拼杀股神谈成功秘诀 原帖:http://www.gupiao168.com/bbs/thread-525275-1-19.html
买日本车的同学,看了这个后再下手http://club.autohome.com.cn/bbs/thread-c-554-8639839-1.html
单亲孩子更需要性别角色教育 本文摘自: 天门社区(www.tmbbs.com) 详细出处请参考:http://www.tmbbs.com/thread-56342-1-1.html 本文摘自: 天门