当前位置: 首页 > news >正文

RTOS接口-Semaphores

跟Linux下面的信号量的PV操作是一个思想

接口

/*Create and Initialize a Semaphore object.*/
osSemaphoreId_t  osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr)/*Get name of a Semaphore object.*/
const char *  osSemaphoreGetName (osSemaphoreId_t semaphore_id)/*Acquire a Semaphore token or timeout if no tokens are available.*/
osStatus_t 	osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout)/*Release a Semaphore token up to the initial maximum count.*/
osStatus_t 	osSemaphoreRelease (osSemaphoreId_t semaphore_id)/*Get current Semaphore token count.*/
uint32_t  osSemaphoreGetCount (osSemaphoreId_t semaphore_id)/*Delete a Semaphore object.*/ 
osStatus_t 	osSemaphoreDelete (osSemaphoreId_t semaphore_id)

代码举例

osSemaphoreId_t multiplex_id;void thread_n (void) {multiplex_id = osSemaphoreNew(3U, 3U, NULL);while(1) {osSemaphoreAcquire(multiplex_id, osWaitForever);// do somethingosSemaphoreRelease(multiplex_id);}
}

当信号量的数量为1时,实现的功能就跟互斥锁没有区别了

http://www.dtcms.com/a/167973.html

相关文章:

  • ADG网络故障恢复演练
  • 实现了一个基于寄存器操作STM32F103C8t6的工程, 并实现对PA1,PA2接LED正极的点灯操作
  • 如何提升个人的稳定性?
  • 蓝桥杯比赛
  • 基于BERT类的MRPC语义相似度检测(从0到-1系列)
  • 机箱结构的EMC设计
  • 5月1日日记
  • Window通过虚拟机17安装Ubuntu20.04并安装相关的插件(胎教级教程)
  • 进程与线程:04 内核线程
  • 2025年4月文章一览
  • 杜邦分析法
  • 实验五 完整性
  • openEuler 22.03 安装 Mysql 5.7,TAR离线安装
  • Java 基础--数组(Array):存储数据的“排排坐”
  • C语言中数字转化为字符串的方法
  • eNSP实验——防火墙 IPSec 配置
  • 【统计方法】方差分析(ANOVA):判断数据差异的统计方法
  • 【dify—9】Chatflow实战——博客文章生成器
  • Java 多线程进阶:线程安全、synchronized、死锁、wait/notify 全解析(含代码示例)
  • linux python3安装
  • 数字智慧方案6145丨智慧学校智能化系统设计方案(53页PPT)(文末有下载方式)
  • CMake中强制启用option定义变量的方法
  • Arduino程序函数从入门到精通
  • Cursor 是什么
  • 【IP101】图像滤波技术详解:从均值滤波到高斯滤波的完整指南
  • C语言-函数的递归和迭代
  • 【大模型】图像生成:ESRGAN:增强型超分辨率生成对抗网络的革命性突破
  • 在 Windows 上启用 Telnet 命令
  • Linux之shell脚本
  • 多商户商城系统开发全策略:从技术架构到流量增长