当前位置:网站首页>B_QuRT_User_Guide(17)
B_QuRT_User_Guide(17)
2022-06-11 02:39:00 【weixin_38498942】
B_QuRT_User_Guide(17)
11 Semaphores
线程使用信号灯来同步访问共享资源。当一个信号灯被初始化时,它被分配一个整数的数值。这个值表示可以通过信号灯同时访问共享资源的线程数量。默认值为1。
当一个线程在一个信号灯上执行down操作时,其结果取决于信号灯的计数值。
- 如果计数值为非零,则被递减,线程获得对共享资源的访问权并继续执行。
- 如果计数值为零,则不会被递减,线程在信号上被暂停。当计数值变为非零时(因为另一个线程释放了该信号),它将被递减,被暂停的线程被唤醒并获得对共享资源的访问权。
当一个线程对一个semaphore进行向上操作时,semaphore的计数值会被递增。其结果取决于在该信号上等待的线程的数量。 - 如果没有线程在等待,则当前线程释放对共享资源的访问并继续执行。
- 如果有一个或多个线程在等待,并且semaphore的数值非零,内核会唤醒优先级最高的等待线程,并递减semaphore的数值。如果被唤醒的线程比当前线程有更高的优先级,就会发生上下文切换。
add操作类似于up,但是可以将semaphore的数值增加到大于1的程度。因此,add有可能在一次操作中唤醒多个等待的线程。
try down操作使线程能够尝试访问共享资源,如果它的semaphore的计数值为0,则不会有被中止的风险。 - 如果计数为非零,则尝试下降操作与常规下降操作相同。
- 如果计数为零,try down会返回一个表示零计数状态的值。Semaphores是共享对象,支持以下操作。
- qurt_sem_add()
- qurt_sem_destroy()
- qurt_sem_down()
- qurt_sem_get_val()
- qurt_sem_init()
- qurt_sem_init_val()
- qurt_sem_try_down()
- qurt_sem_up()
- qurt_sem_down_timed()
- Data Types
11.1 qurt_sem_add()
11.1.1 Function Documentation
11.1.1.1 int qurt_sem_add ( qurt_sem_t ∗ sem, unsigned int amt )
释放对一个共享资源的访问(指定的数量会增加信号灯的数值)。
当一个线程在一个semaphore上执行添加操作时,指定的值会增加semaphore的计数。其结果取决于在该信号上等待的线程数量。
- 当没有线程在等待时,当前线程释放对共享资源的访问并继续执行。
- 当有一个或多个线程在等待,并且semaphore计数为非零时,内核会重复唤醒优先级最高的等待线程,并递减semaphore计数,直到没有等待线程或者semaphore计数为零。如果任何一个被唤醒的线程的优先级高于当前线程,就会发生上下文切换。
相关数据类型
qurt_sem_t
参数
返回值
Unused integer value.
依赖关系
None.
11.2 qurt_sem_destroy()
11.2.1 Function Documentation
11.2.1.1 void qurt_sem_destroy ( qurt_sem_t ∗ sem )
销毁指定的semaphore。
注意:当semaphores不再被使用时,必须将其销毁。如果不这样做会导致QuRT内核的资源泄漏。
Semaphores不能在仍在使用时被销毁。如果发生这种情况,QuRT的行为将无法定义。
相关数据类型
qurt_sem_t
参数
返回值
None.
依赖关系
None.
11.3 qurt_sem_down()
11.3.1 Function Documentation
11.3.1.1 int qurt_sem_down ( qurt_sem_t ∗ sem )
请求访问一个共享资源。当一个线程对一个信号灯进行向下操作时,其结果
取决于semaphore的计数值。
- 当计数值为非零时,它被递减,线程获得对共享资源的访问权并继续执行。
- 当计数值为零时,它不会被递减,线程在信号灯上被暂停。当计数值变为非零时(因为另一个线程释放了该信号),它被递减,被暂停的线程被唤醒并获得对共享资源的访问。
相关数据类型
qurt_sem_t
参数
返回值
Unused integer value.
依赖关系
None.
11.4 qurt_sem_get_val()
11.4.1 Function Documentation
11.4.1.1 static unsigned short qurt_sem_get_val ( qurt_sem_t ∗ sem )
获取semaphore的计数值。
返回指定的semaphore的当前计数值。
相关数据类型
qurt_sem_t
参数
返回值
Integer semaphore count value
依赖关系
None.
11.5 qurt_sem_init()
11.5.1 Function Documentation
11.5.1.1 void qurt_sem_init ( qurt_sem_t ∗ sem )
初始化一个semaphore对象。默认的初始值是1,即semaphore计数值。
参数
返回值
None.
依赖关系
None.
边栏推荐
- HUST Software Engineering (Experiment 2) -- TDD test driven development experiment.
- 巴歇尔槽流量计远程采集物联网关在明渠流量监测的应用
- Manon's advanced road - Daily anecdotes
- Android WiFi hide SSID configuration method
- Shell 按行读取文件
- 基于互联网架构演进, 构建秒杀系统
- CocosCreator原生二次开发的正确姿势
- Niuke: two numbers that only appear once in the array
- AOSP - Developer mode is enabled by default
- Baidu submits sitemap to prompt the solution of "index type is not handled"
猜你喜欢

CocosCreator原生二次开发的正确姿势

. Net module and assembly - NET Module vs Assembly

GraphAcademy 課程講解:《Neo4j 圖數據科學基礎》

AOSP ~ modify WebView default implementation

Explication du cours de graphacademy: neo4j Graph Data Science Foundation

Go quick start of go language (I): the first go program

Error in Solr access: error initializing queryelevationcomponent

msg=SolrCore ‘collection1‘ is not available due to init failure: Could not l

第七章 常用的协议简介(1)

Helm deploy traifik ingress
随机推荐
判断一串数字是否是快速排序某一次的结果
你的公司会选择开发数据中台吗?
AOSP ~ 修改WebView默认实现
Three ways of reflection
CPT 102_LEC 16
[new open source project] dynamic configuration task scheduling framework gobrs async joins the dromara open source community
Navicat premium 15 tool is automatically deleted by anti-virus protection software solution
[Fibonacci series]
Stringutils string tool class used by FreeMarker to create templates
[long time series prediction] aotoformer code detailed [3] model overall architecture analysis
Cygwin reports an error child_ info_ fork::abort: XXX. dll: Loaded to different address: parent(XXX) != child(XXX)
ROS基础 - 使用 launch 文件(一) - 批量启动多个ROS节点
The two departments jointly issued the nine provisions on fire safety management of off campus training institutions
Chapter VII introduction to common protocols (1)
How to state clearly and concisely the product requirements?
Explication du cours de graphacademy: neo4j Graph Data Science Foundation
Android WiFi hide SSID
Recent learning and update plan
Whether the outbound sequence is the inbound sequence
Unity项目优化详解(持续补充ing)