线程
来源:互联网 发布:大数据教程 pdf 编辑:程序博客网 时间:2024/06/04 01:19
#include <stdio.h>
#include <pthread.h>
void *myThread1(void)
{
int i;
for (i=0; i<100; i++)
{
printf("This is the 1st pthread,created by zieckey.\n");
sleep(1);//Let this thread to sleep 1 second,and then continue to run
}
}
void *myThread2(void)
{
int i;
for (i=0; i<100; i++)
{
printf("This is the 2st pthread,created by zieckey.\n");
sleep(1);
}
}
int main()
{
int i=0, ret=0;
pthread_t id1,id2;
/*创建线程1*/
ret = pthread_create(&id1, NULL, (void*)myThread1, NULL);
if (ret)
{
printf("Create pthread error!\n");
return 1;
}
/*创建线程2*/
ret = pthread_create(&id2, NULL, (void*)myThread2, NULL);
if (ret)
{
printf("Create pthread error!\n");
return 1;
}
// pthread_join(id1, NULL);
//pthread_join(id2, NULL);
return 0;
}
#include <pthread.h>
void *myThread1(void)
{
int i;
for (i=0; i<100; i++)
{
printf("This is the 1st pthread,created by zieckey.\n");
sleep(1);//Let this thread to sleep 1 second,and then continue to run
}
}
void *myThread2(void)
{
int i;
for (i=0; i<100; i++)
{
printf("This is the 2st pthread,created by zieckey.\n");
sleep(1);
}
}
int main()
{
int i=0, ret=0;
pthread_t id1,id2;
/*创建线程1*/
ret = pthread_create(&id1, NULL, (void*)myThread1, NULL);
if (ret)
{
printf("Create pthread error!\n");
return 1;
}
/*创建线程2*/
ret = pthread_create(&id2, NULL, (void*)myThread2, NULL);
if (ret)
{
printf("Create pthread error!\n");
return 1;
}
// pthread_join(id1, NULL);
//pthread_join(id2, NULL);
return 0;
}
0 0
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- 线程
- android中自定义span对象的动作
- listview快速滑动条设置
- android动态加载未安装的apk文件中…
- 判断四大应用程序组件是否安装
- 1.3.1Netty 快速入门
- 线程
- 设置对话框在窗口中的位置和透明度
- notifcation的使用以及其支持的可…
- opencv图像旋转--矩阵旋转和仿射变换相比较
- 打开蓝牙的两种方式
- 安卓中批量修改控件字体和样式
- !!! FAILED BINDER&nbsp…
- Leetcode217. Contains Duplicate
- android.database.sqlite.SQLiteDa…