没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
个人信息
(1)我的CSDN博客主页: https://blog.csdn.net/xiaolong1126626497
这篇文章介绍Linux下线程的创建与基本使用案例,主要是案例代码为主;相关的函数详细介绍在上篇文
章里已经介绍过了。
1. 案例代码: 线程的创建
下面这份代码演示如何创建线程。在编译的时候需要加上-lpthread
函数原型:
示例代码:
#include <pthread.h>
int pthread_create
(
pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine) (void *),
void *arg
);
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdlib.h>
//[wbyq@wbyq linux_c]$ gcc app.c -lpthread
/*
线程工作函数
*/
void *thread_work_func(void *dev)
{
int i;
for(i=0;i<5;i++)
{
sleep(1);
printf("子线程正在运行.%d ",i);
}
//终止当前线程执行
pthread_exit(NULL);
}
资源评论
DS小龙哥
- 粉丝: 4w+
- 资源: 522
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功