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;
}
#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;
}
相关文章推荐
- Linux下一个简单的多线程互斥锁的例子
- linux创建、取消多线程的简单实用的模板例子
- Linux DirectFB DFB 简单 初始化 例子 代码
- [转]一个简单的Linux多线程例子 带你洞悉互斥量 信号量 条件变量编程
- 一个简单的Linux多线程例子 带你洞悉互斥量 信号量 条件变量编程
- ios多线程的简单例子
- 利用JAVA多线程采集数据库与Linux主机指标的简单实现
- 最简单的java多线程代码(重写thread或者runnable的run方法)
- 委托 事件 多线程 简单例子
- linux下简单文件加密代码
- linux多进程多线程互斥同步例子
- jetway_loves_programming之linuxC学习之Linux 下Makefile的automake生成简单例子
- linux两个程序通过共享内存通信的一个简单例子
- 一个简单的Linux下Client/Server应答例子
- linux 下net-snmp简单例子
- Linux下多线程的简单调试技巧
- linux组播编程一个简单的例子
- Linux程序代码移植到Windows的简单方法(转)
- Linux下的Shell编程(1)最简单的例子