pthread(1) 创建线程
2013-01-10 21:32
393 查看
程序源码:
vim pthread_sample01.c
/**
* create a new pthread
*/
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
void* do_work(void* arg)
{
printf("i create a new pthread successfully!\n");
}
pthread_t pthread_id;
int main(int argc, char** argv)
{
int result = 0;
result = pthread_create(&pthread_id, NULL, do_work, NULL);
printf("result is: %d\n", result);
sleep(2);
return 0;
}
编译脚本:
vim Makefile
pthread_sample01 : pthread_sample01.c
cc -pthread -o pthread_sample01 pthread_sample01.c
执行结果:
./pthread_sample01
result is: 0
i create a new pthread successfully!
vim pthread_sample01.c
/**
* create a new pthread
*/
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
void* do_work(void* arg)
{
printf("i create a new pthread successfully!\n");
}
pthread_t pthread_id;
int main(int argc, char** argv)
{
int result = 0;
result = pthread_create(&pthread_id, NULL, do_work, NULL);
printf("result is: %d\n", result);
sleep(2);
return 0;
}
编译脚本:
vim Makefile
pthread_sample01 : pthread_sample01.c
cc -pthread -o pthread_sample01 pthread_sample01.c
执行结果:
./pthread_sample01
result is: 0
i create a new pthread successfully!
相关文章推荐
- linux 线程创建 pthread_create函数 获取线程id
- 【Linux学习】pthread_create主线程与创建的新线程之间退出关系
- 线程创建函数pthread_create的pthread_attr_t类型的参数
- linux创建线程之pthread_create
- pthread线程创建出现undefined reference to `pthread_create' collect2: error: ld returned 1 exit status
- 线程的创建,pthread_create,pthread_self,pthread_once
- 用Pthread创建线程的一个简单Demo
- pthread_key_create()--创建线程私有数据|pthread_key_delete()--注销线程私有数据
- c++ Pthread创建线程后必须使用join或detach释放线程资源
- 同一线程多次创建 的 线程资源释放问题在每个线程的一开始,用pthred_detach(pthread_self())来使自己detach掉
- Pthread创建线程后必须使用join或detach释放线程资源
- 线程的创建pthread_create()函数(线程一)
- 线程创建函数pthread_create
- pthread线程创建过程(未完)
- linux c之使用pthread_create创建线程pthread_join等待线程和pthread_exit终止线程总结
- Linux中以PTHREAD_CREATE_DETACHED属性创建线程
- 线程退出【Linux学习】pthread_create主线程与创建的新线程之间退出关系
- 创建线程方式-pthread
- 主进程中如何退出pthread_create创建的线程?
- pthread_create线程创建的过程剖析