Title : pthread-application.c
Author :
Time :
Function :
Comment :
Usage : 1、gcc -o pthread-application pthread-application.c -lpthread 2、./pthread-application
*******************************************************/
#include
#include
#include
#include "pthread.h"
void *thread_func(void *arg);
char message[]="hello";
int main(int argc,char *argv[])
{
int res;
pthread_t a_thread;
void *thread_result;
res=pthread_create(&a_thread,NULL,thread_func,(void *)message);
if(res!=0){
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("waiting for thread to finish....\n");
res=pthread_join(a_thread,&thread_result);
if(res!=0){
perror("thread join failed");
exit(EXIT_FAILURE);
}
printf("thread joined,it returned %s\n",(char *)thread_result);
printf("message is now %s\n",message);
exit(EXIT_SUCCESS);
}
void *thread_func(void *arg)
{
printf("thread_func is running .argument was %s\n",(char*) arg);
sleep(2);
strcpy(message,"bye");
pthread_exit("thank you for the cpu time");
}
aslk12345 于 2010-12-08 17:53:29发表:
Advanced Programing in Unix Envirement
aslk12345 于 2010-12-08 17:50:01发表:
软件开发者路线图:从学徒到高手
yyxl 于 2010-12-08 15:55:40发表:
站跳来跳去就是下不了
看看这次能不能下
少华 于 2010-11-08 20:15:28发表:
学习了
yeqishi 于 2010-04-29 15:10:36发表:
学习,顶
yo 于 2005-09-27 00:43:26发表:
支持