多线程
来源:互联网 发布:vb .net boolean 判断 编辑:程序博客网 时间:2024/06/05 11:10
void *func_1(void *args)
{
while(1)
{
Sleep(1);
printf("this is func_1!\n");
}
}
void *func_2(void *args)
{
while(1)
{
Sleep(2);
printf("this is func_2!\n");
}
}
void main()
{
/* unsigned int */
pthread_t pid1, pid2;
/* 创建线程函数,func_1:线程运行函数的起始地址 */
if(pthread_create(&pid1, NULL, func_1, NULL))
{
return -1;
}
if(pthread_create(&pid2, NULL, func_2, NULL))
{
return -1;
}
while(1)
{
Sleep(3);
}
return;
{
while(1)
{
Sleep(1);
printf("this is func_1!\n");
}
}
void *func_2(void *args)
{
while(1)
{
Sleep(2);
printf("this is func_2!\n");
}
}
void main()
{
/* unsigned int */
pthread_t pid1, pid2;
/* 创建线程函数,func_1:线程运行函数的起始地址 */
if(pthread_create(&pid1, NULL, func_1, NULL))
{
return -1;
}
if(pthread_create(&pid2, NULL, func_2, NULL))
{
return -1;
}
while(1)
{
Sleep(3);
}
return;
}
编译:
gcc -thread.c -o thread -lpthread
执行:
./thread
因为pthread并非Linux系统默认库,为静态链接库,所以在编译时要加上 -lpthread参数。
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 多线程
- 数据结构C语言版(答案)
- 数据对齐
- 关于Activity的基础
- blackhat 2010 download
- hdu 4055 Number String
- 多线程
- windows程序逆向工具汇总
- myeclipse10中导入的jquery文件报错(出现红叉叉,提示语法错误)
- [转] C语言的谜题
- 正则表达式
- usaco range java
- syncback 30天xx
- Java连接MySQL数据库并查询结果
- CString,string,char*的综合比较及相互转换