linux下线程的创建和管理
来源:互联网 发布:seo编辑工具 编辑:程序博客网 时间:2024/06/01 20:55
#include<stdio.h>#include<stdlib.h>#include<pthread.h>#include<string.h>char msg[]="Hello";void* thread_function(void*);int main(){ int res=-1; pthread_t th={0}; printf("the mem is %s\n",msg); res=pthread_create(&th,NULL,thread_function,(void*)msg); if(0!=res) { printf("sorry the thread create failed\n"); exit(0); } //开始合并线程,也即等待线程执行完之后才能继续向下执行,thread_res是pthread_exit中的值 void* thread_res=NULL; res=pthread_join(th,&thread_res); if(0!=res) { printf("thread_join failed \n"); exit(0); } printf("thread exit successfully!the return is :%s\n",(char*)thread_res); printf("the mem is %s\n",msg); exit(0); return 0;}void* thread_function(void* msg){ printf("this is thread output\n"); //休眠3秒 sleep(3); strcpy((char*)msg,"youto"); pthread_exit("线程执行完毕");}
恩,恩,还有对应的makefile文件如下:
test: thread.ogcc -o test thread.o -lpthreadthread.o:thread.cgcc -c thread.cclean:rm test *.o
0 0
- linux下线程的创建和管理
- linux下线程的创建和等待
- Linux下线程的创建
- Linux下线程的创建
- Linux下线程的创建
- linux下线程的创建
- linux下线程的创建
- linux下线程的创建
- linux 下线程的创建
- 嵌入式 Linux下线程的创建和启动
- 《linux下线程的创建,同步和退出》
- ACE中线程的创建和管理
- Linux下的进程类别(内核线程、轻量级进程和用户进程)以及其创建方式--Linux进程的管理与调度(四)
- linux 下创建线程
- linux下创建线程
- linux下创建用户线程和内核线程
- Linux下的通用线程池创建
- Linux下的通用线程池创建
- 【暴力搜索】[POJ 1186]方程的解数
- PHP多进程处理并行处理任务实例
- OC多文件编译分析
- C#在窗体中点击任意位置鼠标左键获得该点坐标
- 计算两个时间戳之间的工作日间隔时间(9:30-12:00 13:00-18.30)
- linux下线程的创建和管理
- WSTMall开源系统助力站长,以店铺为据点做分布式O2O
- Redis和Memcache 区别
- 杭电1014
- 配置網橋的case
- 拨号器的实现
- Linux内核基础--事件通知链(notifier chain)
- C#中Array类的使用
- GRE写作必备句型