您的位置:首页 > 运维架构 > Linux

linux 多线程 最简单 例子 代码

2010-12-21 00:19 302 查看
#include "pthread.h"
#include "stdio.h"
#include "stdlib.h"

void* thread_func1(void *arg)
{
int *val = arg;
printf("Hi, I'm a thread/n");
if(NULL!=arg)
{
while(1)
{
printf("Argument Set : %d/n",*val);
}
}
}

int main()
{
pthread_t tid;
int t_arg = 100;

if(pthread_create(&tid,NULL,thread_func1,&t_arg))
perror("Fail to Create thread");

sleep(3);
printf("Main thread!/n");
pthread_cancel(tid);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: