摘要: /*初始化属性int pthread_attr_init(pthread_attr_t *tattr);函数将对象属性初始化为其缺省值。分配一些存储空间,所以需要下面的函数删除初始化期间分配的存储空间。int pthread_attr_destroy(pthread_attr_t *tattr);以... 阅读全文
posted @ 2014-09-26 23:43 南哥的天下 阅读(2928) 评论(0) 推荐(0)
摘要: #include #include #include #include //取消线程,是否会释放线程的所有资源?例子:void *thread1(void *arg){ printf("start thread (%u)\n", (unsigned)pthread_self());} ... 阅读全文
posted @ 2014-09-26 23:39 南哥的天下 阅读(1110) 评论(0) 推荐(0)
摘要: /*0.取消线程 int pthread_cancel(pthread_t thread);设置取消点 void pthread_testcancel(void);测试是否接收到取消请求,如果有,结束线程。例子:*/#include #include #include #include int... 阅读全文
posted @ 2014-09-26 23:37 南哥的天下 阅读(1393) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 #include 5 void *consumer(void *p) 6 { 7 int i; 8 printf("start (%d)\n", (int)p); 9 ... 阅读全文
posted @ 2014-09-26 23:35 南哥的天下 阅读(3637) 评论(0) 推荐(0)
摘要: /*一次性初始化int pthread_once(pthread_once_t *once_control, void (*init_routine) (void))本函数使用初值为PTHREAD_ONCE_INIT的once_control变量保证init_routine()函数在本进程执行序列中... 阅读全文
posted @ 2014-09-26 23:33 南哥的天下 阅读(851) 评论(0) 推荐(0)
摘要: /*http://hankjin.blog.163.com/blog/static/33731937201072675024100/pthread的内存泄露 # cc thread.c -lpthread# ./a.out1 threads created101 threads created20... 阅读全文
posted @ 2014-09-26 23:05 南哥的天下 阅读(1593) 评论(0) 推荐(0)