pthread_create()函数样例
2017-05-18 14:42
519 查看
#include <stdio.h> #include <pthread.h> #include <unistd.h> void* client_pthread(void* arg) { printf("call client_pthread()\n"); while(1) { sleep(3); printf("call client_pthread()\n"); } } void* client_pthread_two(void* date_two) { printf("call client_pthread_two()\n"); while(1) { sleep(3); printf("call client_pthread_two()\n"); } } void test_pthread_client(void) { int ret = 0; pthread_t pthread_id; pthread_t pthread_id_two; printf("call test_pthread_client()\n"); ret = pthread_create(&pthread_id, NULL, client_pthread, NULL); if(0 != ret) { printf("create pthread false\n"); return; } ret = pthread_create(&pthread_id_two, NULL, client_pthread_two, NULL); if(0 != ret) { printf("create pthread false\n"); return; } pthread_join(pthread_id,NULL); //加入pthread_join后,主线程会一直等待直到等待的线程结束自己才结束,使创建的线程有机会执行。 pthread_join(pthread_id_two,NULL); } int main() { printf("call main()\n"); test_pthread_client(); return 0; }
相关文章推荐
- pthread_create()函数样例
- pthread_create 函数的安全使用
- [转]pthread_create函数编译时报错:undefined reference to 'pthread_c...
- Linux多线程函数pthread_create()函数
- eclipse 函数编译时报错:undefined reference to `pthread_create’
- pthread_create()函数
- pthread_create()和pthread_atfork()函数使用时应注意的问题
- c++里的 pthread_create 函数小结
- pthread_create、readlink、getpid等函数的学习与总结
- pthread_create()函数参数使用心得
- pthread_create使用类中函数指针的…
- pthread_create 函数
- pthread_create 函数用法
- 解决使用pthread_create函数造成的内存泄露
- 基于pthread_create,readlink,getpid等函数的学习与总结
- pthread_create、readlink、getpid等函数的学习与总结
- linux编程之pthread_create函数
- pthread_create函数编译时报错:undefined reference to 'pthread_create'
- c++里的 pthread_create 函数小结
- pthread_create使用类中函数指针的…