javascript和JQuery焦点图和代码特效大全
当前最流行的开源CMS网站系统大全
当前位置:主页 > 操作系统 > Linux/Unix >

linux线程创建是实现方法

来源:IT技术网编辑:香独秀发布于:2011-04-05人围观Linux方法线程创建是

linux线程创建是实现方法.

#include
#include
#include
#include
void *thread_function(void *arg);
char message[]="Hello World!";
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("THread creation failed");
	exit(EXIT_FAILURE);
	}
     printf("waiting for thread to finish.....\n");
     res=pthread_join(a_thread,&thread_result);
     if(res!=0){
	printf("Waiting for thread jioned failed\n");
	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_function(void *arg)
{
     printf("thread_funvtion is nowrunning .Arguement was %s\n",(char*)arg);
     sleep(3);
     strcpy(message,"Bye!");
     pthread_exit("Thank you for CPU time");
}

Linux,方法,线程,相关的文章
有时间的话来看看IT界的突发事件