当前位置:网站首页>B_ QuRT_ User_ Guide(20)
B_ QuRT_ User_ Guide(20)
2022-06-11 03:00:00 【weixin_ thirty-eight million four hundred and ninety-eight thou】
B_QuRT_User_Guide(20)
13 Condition variables,
Threads use conditional variables to synchronize their execution based on values in shared data items . Conditional variables are useful in situations where a thread must normally continuously poll a data item until it contains a specific value —— Using conditional variables, threads can accomplish the same task without polling .
Condition variables are always associated with mutexes ( The first 5 section ) Use it together , To ensure that shared data items are checked and updated without thread contention .
For threads waiting for specific conditions of shared data items , It must first lock the mutex that controls access to the data item . If the conditions are not met , Then the thread performs the wait condition operation on the condition variable ( Suspend the thread and unlock the mutex ).
For a thread, send a signal that the condition is true on the shared data item , It must first lock the mutex that controls access to the data item , Then perform the signal condition operation , Finally, the mutex is explicitly unlocked .
Signal condition operation is used to wake up a single waiting thread . If multiple threads are waiting for a condition variable , They can all be awakened by broadcast conditional operation .
Be careful : Failure to properly lock and unlock mutexes using conditional variables may cause the thread to never hang ( Or pause but never wake up ).
because QuRT Allow the thread to be awakened by false conditions , So the thread should always verify the target condition when it is awakened .
Condition variables are shared objects that support the following operations :
- qurt_cond_broadcast()
- qurt_cond_destroy()
- qurt_cond_init()
- qurt_cond_signal()
- qurt_cond_wait()
- qurt_cond_wait2()
- Data Types
13.1 qurt_cond_broadcast()
13.1.1 Function document
13.1.1.1 void qurt_cond_broadcast ( qurt_cond_t ∗ cond )
Notify multiple waiting threads that the specified condition is true .
When a thread wants to broadcast a condition that is true on a shared data item , It must perform the following process :
- Lock mutexes that control access to data items .
- Perform broadcast condition operation .
- Unlock the mutex .
Be careful : Failure to properly lock and unlock mutexes of condition variables may cause the thread to never hang ( Or pause but never wake up ).
Use condition variables only with regular mutexes —— Trying to use recursive mutexes or priority inheritance mutexes can lead to undefined behavior .
Related data types
qurt_cond_t
Parameters
| in | cond | Pointer to the conditional variable object to signal . |
Return value
None.
Dependency relationship
None.
13.2 qurt_cond_destroy()
13.2.1 Function document
13.2.1.1 void qurt_cond_destroy ( qurt_cond_t ∗ cond )
Destroy the specified condition variable .
Be careful : Conditions must be destroyed when they are no longer in use . Failure to do so will result in QuRT A resource leak in the kernel .
Do not destroy the conditions that are still in use . If this happens , be QuRT The behavior of is undefined .
Related data types
qurt_cond_t
Parameters
| in | cond | Pointer to the condition variable object to destroy . |
Return value
None.
13.3 qurt_cond_init()
13.3.1 Function document
13.3.1.1 void qurt_cond_init ( qurt_cond_t ∗ cond )
Initialize a condition variable object .
Related data types
qurt_cond_t
Parameters
| out | cond | Pointer to initialized condition variable object . |
Return value
None.
Dependency relationship
None.
13.4 qurt_cond_signal()
13.4.1 Function document
13.4.1.1 void qurt_cond_signal ( qurt_cond_t ∗ cond )
Notifies the waiting thread that the specified condition is true .
When a thread wants to signal that a condition is true on a shared data item , It must perform the following process :
- Lock mutexes that control access to data items .
- Perform signal condition operation .
- Unlock the mutex .
Be careful : Failure to properly lock and unlock mutexes on condition variables may cause the thread to never hang ( Or pause but never wake up ).
Use condition variables only with regular mutexes —— Trying to use recursive mutexes or priority inheritance mutexes can lead to undefined behavior .
Related data types
qurt_cond_t
Parameters
| in | cond | Pointer to the conditional variable object to signal . |
Return value
None.
Dependency relationship
None.
13.5 qurt_cond_wait()
13.5.1 Function document
13.5.1.1 void qurt_cond_wait ( qurt_cond_t ∗ cond, qurt_mutex_t ∗ mutex )
Suspends the current thread , Until the specified condition is true . When a thread wants to wait for a specific condition for a shared data item , It must perform the following process :
- Lock mutexes that control access to data items .
- If the conditions are not met , Wait for the condition variable ( Hung thread , Unlock the mutex ).
Be careful : Failure to properly lock and unlock mutexes of condition variables may cause the thread to never hang ( Or pause but never wake up ).
Use condition variables only with regular mutexes —— Trying to use recursive mutexes or priority inheritance mutexes can lead to undefined behavior .
Related data types
qurt_cond_t
qurt_mutex_t
Parameters
| in | cond | Pointer to the condition variable object to wait for . |
| in | mutex | Pointer to the mutex associated with the condition variable to wait for . |
Return value
None.
Dependency relationship
None.
13.6 qurt_cond_wait2()
13.6.1 Function document
13.6.1.1 void qurt_cond_wait2 ( qurt_cond_t ∗ cond, qurt_rmutex2_t ∗ mutex )
Suspends the current thread , Until the specified condition is true . When a thread wants to wait for a specific condition for a shared data item , It must perform the following process :
- Lock mutexes that control access to data items .
- If the conditions are not met , Wait for the condition variable ( Hung thread , Unlock the mutex ).
Be careful : Failure to properly lock and unlock mutexes of condition variables may cause the thread to never hang ( Or pause but never wake up ).
Use condition variables only with regular mutexes —— Trying to use recursive mutexes or priority inheritance mutexes can lead to undefined behavior .
This is the qurt_cond_wait() same API, In the use of qurt_rmutex2_t This version is used for mutexes of type .
Related data types
qurt_cond_t
qurt_rmutex2_t
Parameters
| in | cond | Pointer to the condition variable object to wait for . |
| in | mutex | Pointer to the mutex associated with the condition variable to wait for . |
Return value
None.
Dependency relationship
None.
13.7 data type
This section describes the data types of conditional variable services .
- Conditional variables in QuRT Said to qurt_cond_t Object of type .
13.7.1 Data structure document
13.7.1.1 union qurt_cond_t
QuRT Condition variable type .
边栏推荐
- 【新晋开源项目】动态配置化任务编排框架 Gobrs-Async 加入Dromara开源社区
- ROS基础 - 使用 launch 文件(一) - 批量启动多个ROS节点
- 数据库唯一索引和普通索引的区别?
- 码农的进阶之路 | 每日趣闻
- RS232/RS485转4G DTU 上传基于Modbus协议的温湿度传感器数据到远程TCP服务器
- 2022年熔化焊接与热切割操作证考试题库及答案
- 二叉树最小最低公共祖先
- B_QuRT_User_Guide(19)
- Fuluo classic source code Fuluo classic system development principle sharing
- Live broadcast! Feature matching of orb-slam3 series (mlpnp, word bag model, etc.).
猜你喜欢

How to add two factor authentication for WordPress websites

How can Delma's own brand "take off" when Philips is listed on the market?

What is ttfb

How to add cookie pop-up window in WordPress website (without plug-in)

The two request sessionids of the same user are inconsistent ----- record the problem

怎样简洁明了地说清楚产品需求?

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

Graphacademy course explanation: Fundamentals of neo4j graph data science

Google Gmail mailbox marks all unread messages as read at once

Go语言之Go 快速入门篇(一):第一个 Go 程序
随机推荐
Blue Bridge Cup_ Xiao Lan eats candy_ Pigeon nest principle / drawer principle
js 内存泄漏
CPT 102_ LEC 17
Question bank and answers for 2022 melting welding and thermal cutting operation certificate examination
[new open source project] dynamic configuration task scheduling framework gobrs async joins the dromara open source community
微信模版消息errcode“:40165,“errmsg“:“invalid weapp pagepath
CPT 102_LEC 13-14
CPT 102_LEC 20
牛客网:数组中只出现一次的两个数字
CPT 102_ LEC 15
How to add cookie pop-up window in WordPress website (without plug-in)
AOSP ~ WiFi on by default + GPS off by default + Bluetooth off by default + rotary screen off
Young people fleeing big cities: shouldering housing prices and pressure, but not epidemics
intXX_ T and int_ fastXX_ T what is the difference- What is the difference between intXX_ t and int_ fastXX_ t?
靠贴牌飞利浦冲击上市,德尔玛的自有品牌又该如何“起跳”?
20220610 Friday
The Google search console webmaster tool cannot read the sitemap?
富络经典源码富络经典系统开发原理分享
蓝桥杯_小蓝吃糖果_鸽巢原理 / 抽屉原理
CPT 102_ LEC 20