|
* main.c
*
* Created on: 2016-4-25
* Author: bishenle
*/
#include
#include
#include
#include
#include
void *thread_function(void *arg);
char message[]="THREAD_TEST";
int main()
{
int res;
pthread_t a_thread;
void *thread_result;
res=pthread_create(&a_thread,NULL,thread_function,(void *)message);
if(res!=0){
perror("线程创建失败");
exit(EXIT_FAILURE);
}
printf("等待线程结束...\n");
res=pthread_join(a_thread,&thread_result);
if(res!=0){
perror("等待线程结束失败");
exit(EXIT_FAILURE);
}
printf("线程以结束,返回值:%s\n",(char *)thread_result);
printf("Message的值为:%s\n",message);
exit(EXIT_SUCCESS);
}
void *thread_function(void *arg)
{
printf("线程在运行,参数为:%s\n",(char *)arg);
sleep(3);
strcpy(message,"线程修改");
pthread_exit("线程执行完毕");
}
|
|