创建一个线程_续
来源:互联网 发布:行业roe数据查询 编辑:程序博客网 时间:2024/05/17 08:11
/*************************************************************************> File Name: thread_create.c> Author: laiyehua> Mail: ok.4444@qq.com> Created Time: Sun 29 Dec 2013 11:00:32 AM CST ************************************************************************/#include<stdio.h>#include<stdlib.h>#include<string.h>#include<unistd.h>#include<pthread.h>/************************************************************** * 函数功能:显示线程相应函数执行结果 * 参数一:返回结果 * 参数二:执行函数 *************************************************************/void disp_state_message(int ret, char *msg){ /*线程函数基本上返回0表示成功*/ if(ret != 0) { printf("%s error\n", msg); exit(EXIT_FAILURE); }}/**************************************************************** * 函数功能:新创建的线程开始执行的函数 * 参数一:线程创建时,传递过来参数 * 返回:线程退出时,返回的值 ***************************************************************/void *thread_function(void *arg){ printf("thread_function runing..............\n"); printf("%s\n", (char *)arg); pthread_exit("hi!");}int main(void){ int ret;//返回结果 pthread_t tid;//创建线程ID号 void *result; ret = pthread_create(&tid, NULL, thread_function, "hello thread_function!");//新创建一个线程,给线程传递参数"hello thread_function!" disp_state_message(ret, "pthread_create");//显示创建结果 printf("main runing..............\n"); //usleep(1000);//让出本线程,让其它线程有机会执行 ret = pthread_join(tid, &result);//等待线程结果,如果创建的线程不是分离线程,应该使用这个函数回收线程的资源 disp_state_message(ret, "pthread_join"); printf("result:%s\n", (char *)result); exit(EXIT_SUCCESS);}
0 0
- 创建一个线程_续
- 互斥体_创建4线程_打印
- 1.1.线程基础_创建线程
- 一个线程创建另一个线程
- 创建一个新线程
- 创建一个线程
- 创建一个线程
- 创建一个线程
- win32创建一个线程
- 创建一个线程
- MFC创建一个线程
- 黑马程序员_线程池创建实例
- Java_多线程_创建及启动线程
- 309_子线程创建Handler
- 创建一个线程的方法
- Unix/Linux创建一个线程
- 用ace创建一个线程
- 创建一个简单的线程
- Steps
- 测试图片
- 这些年我所领悟到的(一)
- Total Commander 使用技巧
- spring学习之@ModelAttribute运用详解
- 创建一个线程_续
- 程序开发中,资源文件的存放原则
- spring学习之@SessionAttributes运用详解
- DELPHI判断是否64位操作系统
- ArcGISServer服务访问时“Data not available”设置
- 使用node.js + express开发web应用笔记(3) - 模板页与局部视图
- Combination Sum II
- 在Code::Blocks里面设置SDL工程的方法
- android—两个月的沉积