当前位置:网站首页>Use of serial queues
Use of serial queues
2022-07-24 23:27:00 【Hanyang Li】
1. Declare member variables
/**
GCD Global queues are provided in
however , In a third-party framework , For greater flexibility , You usually create queues yourself
*/
@interface ViewController (){
// Serial queue member variables
dispatch_queue_t _queue;
}
@end2. Initialize the creation of serial queues
_queue = dispatch_queue_create("com.me.queue", DISPATCH_QUEUE_SERIAL);3. test
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self demo1];
}
/// Serial queue front set use Asynchronous normal , Synchronization will hang up , Wait for each other
-(void) demo1 {
// Serial queue , Synchronous execution cannot be nested
dispatch_sync(_queue, ^{
NSLog(@"AAAAAA");
dispatch_sync(_queue, ^{
NSLog(@"BBBBB");
});
});
}
/// Demonstration of serial queue
-(void) demo{
for (int i = 0; i<10; i++) {
// Time consuming operations require asynchronous execution
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// Database operation needs to be guaranteed at the same time , There can only be one operation
// Synchronous execution - Serial threads have no ability to open threads
// Sync , Able to , Even when executing all database operation tasks asynchronously , It can still guarantee the order
dispatch_sync(_queue, ^{
NSLog(@"%@ %d",NSThread.currentThread, i);
});
});
}
}边栏推荐
- Pointrender parsing
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 6
- 物联网平台返回数据解析时遇到org.json.JSONException: No value for Value怎么办
- HLS编程入门
- Notes of Teacher Li Hongyi's 2020 in-depth learning series 2
- P3201 [HNOI2009] 梦幻布丁 启发式合并
- Cross entropy loss
- QT | event system qevent
- 高阶产品如何提出有效解决方案?(1方法论+2案例+1清单)
- Salesforce zero foundation learning (116) workflow - & gt; On flow
猜你喜欢

Network Security Learning (IV) user and group management, NTFS

Convex optimization Basics

HLS编程入门

把字符串转换成整数与不要二

聊聊 Redis 是如何进行请求处理

Notes of Teacher Li Hongyi's 2020 in-depth learning series 8

Bug summary

QT6 with vs Code: compiling source code and basic configuration

生成式对抗网络的效果评估

Zheng Huijuan: Research on application scenarios and evaluation methods of data assets based on the unified market
随机推荐
Simple message queue implementation nodejs + redis =mq
RichTextBox save as picture
Notes of Teacher Li Hongyi's 2020 in-depth learning series 3
凸优化基础知识
中金证券新课理财产品的收益有百分之六吗?我想要开户理财
The specified data is grouped and the number of repetitions is obtained in Oracle
Notes of Teacher Li Hongyi's 2020 in-depth learning series 6
JS ------ Chapter II JS logic control
ShardingSphere-数据库分库分表简介
QT6 with vs Code: compiling source code and basic configuration
Okaleido tiger NFT即将登录Binance NFT平台,后市持续看好
老杜Servlet-JSP
常用在线测试工具集合
Financial products can reach 6%. I want to open an account to buy financial products
How painful is it to write unit tests? Can you do it
Detailed explanation of zhanrui Huben T310: introduce the big core and dynamiq architecture into the entry-level market for the first time!
Can the income of CICC securities' new customer financial products reach 6%? How to open an account?
About the word 'don't remember'
必会面试题:1.浅拷贝和深拷贝_浅拷贝
PGPLSQL中的:=和=