linux——多线程

重要概念

在Linux中没有专门用于多线程的调度算法或者数据结构,而是一种特殊的轻量级进程,拥有独特的task_struct结构体,并共享某些资源。

实现多线程

1. 利用POSIX多线程API开发

包含头文件pthread.h

API 含义
pthread_create 创建
pthread_join 等待一个线程结束
pthread_self 获取线程ID
pthread_cancel 取消一个线程
pthread_exit 退出线程函数
pthread_kill 向线程发送一个信号

线程优先级

//创建线程
pthread_attr_t attr;
struct sched_param param;
pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, SCHED_RR);
param.sched_priority = 49;
pthread_attr_setschedparam(&attr, &param);

pthread_err = pthread_create(&thIspRun , &attr, sdk_isp_run_proc , NULL);
if(pthread_err != 0)
{
  printf("[ISP_LIB]:pthread_create isp pthread error.\n"); 
}
pthread_attr_destroy(&attr);
posted @ 2023-04-18 14:56  爱喝拿铁  阅读(72)  评论(0)    收藏  举报