多线程相关知识
2017-01-05 16:57
281 查看
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #define NUM_THREADS 4 typedef struct{ int threadId; }threadParm_t; void *threadFunc(void *parm) { threadParm_t *p=(threadParm_t *)parm; fprintf(stdout,"Hello world from thread%d\n",p->threadId); pthread_exit((void *)&(p->threadId)); return 0; } int main(int argc,char *argv[]) { int i; int *res; res=(int *)malloc(sizeof(int)); pthread_t thread[NUM_THREADS]; threadParm_t threadParm[NUM_THREADS]; for(i=0;i<NUM_THREADS;i++) { threadParm[i].threadId=i; pthread_create(&thread[i],NULL,threadFunc,(void *)&threadParm[i]); } for(i=0;i<NUM_THREADS;i++) { pthread_join(thread[i],(void **)&res); fprintf(stdout,"Thread %d has exited.\n",*res); } system("pause"); return 0; }
参考网址:http://blog.chinaunix.net/uid-26275986-id-3886498.html
参考网址:http://blog.csdn.net/morewindows/article/details/17488865
参考网址:http://blog.csdn.net/yasi_xi/article/details/19112077 pthread_mutex_lock
参考网址:http://www.linuxcommand.org/man_pages/gcc1.html
相关文章推荐
- 详细讲解在实例中.NET多线程执行函数相关知识
- 多线程相关基础知识
- C# 多线程、异步线程、线程池相关知识
- 多线程相关知识
- 多线程相关知识梳理
- 多线程 相关知识
- 知识储备—01-进程,线程,多线程相关总结
- C# 多线程、异步线程、线程池相关知识
- 关于pyhton多线程的相关知识集合
- 了解一些多线程相关的知识
- 多线程相关知识
- 多线程相关知识(2015年 10月28号 (更新))
- Java多线程相关知识
- C# 多线程、异步线程、线程池相关知识
- C# 多线程、异步线程、线程池相关知识
- C#多线程和socket的相关知识
- (6) Java多线程 线程状态等相关知识(含单例懒汉式饿汉式)
- java 多线程相关知识
- Android多线程相关知识总结——源码分析
- java多线程相关知识