当前位置:网站首页>B_ QuRT_ User_ Guide(17)
B_ QuRT_ User_ Guide(17)
2022-06-11 03:08:00 【weixin_ thirty-eight million four hundred and ninety-eight thou】
B_QuRT_User_Guide(17)
11 Semaphores
Threads use semaphores to synchronously access shared resources . When a semaphore is initialized , It is assigned an integer value . This value indicates the number of threads that can simultaneously access shared resources through the semaphore . The default value is 1.
When a thread executes on a semaphore down In operation , The result depends on the count value of the signal lamp .
- If the count value is non-zero , Is decremented , The thread gains access to the shared resource and continues execution .
- If the count value is zero , Will not be decremented , The thread is suspended on the signal . When the count value becomes non-zero ( Because another thread released the signal ), It will be decremented , The suspended thread wakes up and gains access to the shared resource .
When a thread to a semaphore When working up ,semaphore The count value of is incremented . The result depends on the number of threads waiting on the signal . - If no thread is waiting , The current thread releases access to shared resources and continues execution .
- If one or more threads are waiting , also semaphore The value of is non-zero , The kernel wakes up the waiting thread with the highest priority , And decreasing semaphore The numerical . If the awakened thread has a higher priority than the current thread , Context switching will occur .
add The operation is similar to up, But you can put semaphore The value of is increased to be greater than 1 The degree of . therefore ,add It is possible to wake up multiple waiting threads in one operation .
try down Operation enables a thread to attempt to access a shared resource , If it's semaphore The count value of is 0, There is no risk of suspension . - If the count is non-zero , Then the attempted lowering operation is the same as the conventional lowering operation .
- If the count is zero ,try down A value representing the zero count status will be returned .Semaphores It's a shared object , The following operations are supported .
- 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 )
Release access to a shared resource ( The specified number will increase the number of semaphores ).
When a thread is in a semaphore When performing an add operation on , The specified value increases semaphore Count of . The result depends on the number of threads waiting on the signal .
- When no thread is waiting , The current thread releases access to shared resources and continues execution .
- When there is one or more threads waiting , also semaphore When the count is non-zero , The kernel will repeatedly wake up the waiting thread with the highest priority , And decreasing semaphore Count , Until there is no waiting thread or semaphore The count is zero . If any awakened thread has a higher priority than the current thread , Context switching will occur .
Related data types
qurt_sem_t
Parameters
Return value
Unused integer value.
Dependency relationship
None.
11.2 qurt_sem_destroy()
11.2.1 Function Documentation
11.2.1.1 void qurt_sem_destroy ( qurt_sem_t ∗ sem )
Destroy designated semaphore.
Be careful : When semaphores When it's no longer in use , It must be destroyed . Failure to do so will result in QuRT Kernel resource leak .
Semaphores Cannot be destroyed while still in use . If this happens ,QuRT The behavior of will not be defined .
Related data types
qurt_sem_t
Parameters 
Return value
None.
Dependency relationship
None.
11.3 qurt_sem_down()
11.3.1 Function Documentation
11.3.1.1 int qurt_sem_down ( qurt_sem_t ∗ sem )
Request access to a shared resource . When a thread moves down a semaphore , As a result,
Depending on semaphore The count of .
- When the count value is non-zero , It is decremented , The thread gains access to the shared resource and continues execution .
- When the count is zero , It will not be decremented , Thread is suspended on semaphore . When the count value becomes non-zero ( Because another thread released the signal ), It is decremented , The suspended thread wakes up and gains access to the shared resource .
Related data types
qurt_sem_t
Parameters
Return value
Unused integer value.
Dependency relationship
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 )
obtain semaphore The count of .
Returns the specified semaphore The current count of .
Related data types
qurt_sem_t
Parameters 
Return value
Integer semaphore count value
Dependency relationship
None.
11.5 qurt_sem_init()
11.5.1 Function Documentation
11.5.1.1 void qurt_sem_init ( qurt_sem_t ∗ sem )
Initialize a semaphore object . The default initial value is 1, namely semaphore Count value .
Parameters 
Return value
None.
Dependency relationship
None.
边栏推荐
- Fuluo classic source code Fuluo classic system development principle sharing
- B_QuRT_User_Guide(19)
- sonarqube平台基础使用
- [new open source project] dynamic configuration task scheduling framework gobrs async joins the dromara open source community
- R分析可视化实用数据(航班_教育_餐厅_租户_变迁_寿命_安全)
- 三维GIS行业需求及展望
- Hqchart nailing applet tutorial 1- create a K-line diagram
- CPT 102_ LEC 15
- Flink开发环境搭建及WordCount
- Young people fleeing big cities: shouldering housing prices and pressure, but not epidemics
猜你喜欢

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

Wechat applet

B_QuRT_User_Guide(17)

计算机视觉(AI)面试大全

If you understand the logic of mining and carbon neutrality, you will understand the 100 billion market of driverless mining areas

删除CSDN上传图片的水印

Young people fleeing big cities: shouldering housing prices and pressure, but not epidemics

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

Solr initialization failure: requesthandler INIT failure

怎样确保消息的可靠性投递?
随机推荐
Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
Log4j:error category option "1" not a decimal integer
Solr initialization failure: requesthandler INIT failure
cv. Matchtemplate image model matching opencv
UBIFS FAQ and HOWTO
C语言数组的简单认识
PIP installation Qt5.
Go quick start of go language (I): the first go program
Longest increasing subsequence
位置数据融合表3
二叉树最小最低公共祖先
Multivalued mapping: arraylistmultimap and hashmultimap
In June, 2022, China Database ranking: tidb made a comeback to win the crown, and Dameng was dormant and won the flowers in May
Wechat applet
ASLR
【云原生】什么是微服务?怎么搭建?手把手教你搭建第一个微服务(框架)
Pyqt5: button control
The new colleague asked me what "where 1=1" means???
【大咖秀】博睿数据眼中的AIOps,选择正确的赛道正确的人
CPT 102_ LEC 17