Linux 线程(创建/等待/终止)
2012-09-15 16:35
337 查看
/* FirstThreadFunc.c*/ #include <stdio.h> //#include <unistd.h> //#include <stdlib.h> #include <pthread.h> void thread (void) { // sleep(1); int i; int tid = pthread_self();//返回自己的线程ID for (i = 0; i < 3; i++) printf ("This is a pthread\n"); pthread_exit("hello world!!\n");//把字符串的首地址传给thread_result } int main (void) { void *thread_result; pthread_t id; int i, res; res = pthread_create(&id, NULL, (void *) thread, NULL);//创建线程 pthread_join(id, &thread_result);//等待id的线程结束 if(res != 0) { printf ("Create pthread error!\n"); exit (1); } // sleep(1); for (i = 0; i < 3; i++) printf ("This is the main process\n"); printf("thread joined ,it returned %s\n",(char *)thread_result); return (0); }
相关文章推荐
- Linux-线程(一)创建 终止 等待线程
- [置顶] 【Linux】线程总结:初识、创建、等待、终止、分离
- 【Linux】线程(概念、特点、线程控制代码--创建/等待/终止、分离与结合属性)
- Linux 线程(创建/等待/终止)
- Linux 线程(创建/等待/终止)
- Linux之线程的创建、等待、终止及分离
- 简单的,线程创建,线程等待,线程终止。
- 线程的创建、等待、终止、分离、同步和互斥
- 线程的创建、终止、等待基本操作
- Linux下进程创建, 等待, 终止
- Linux下多线程编程__线程的创建pthread_create与退出pthread_exit,等待当前线程退出pthread_join,获取线程ID pthread_self
- 【线程】多线程创建,传参,共享数据,终止,等待,清除
- linux c之使用pthread_create创建线程pthread_join等待线程和pthread_exit终止线程总结
- 线程的创建、等待与终止
- [置顶] Linux进程(二)进程创建,等待,终止
- JAVA笔记13__创建线程/线程休眠/等待线程终止/线程中断/守护线程
- Linux学习-线程的创建和终止-(出现错误-undefined reference to 'pthread_create')
- 线程创建、等待、终止
- 线程的创建、等待及终止
- Linux进程创建、等待、终止以及vfork&return详解