Dispatch Queues and Thread Safety
Dispatch Queues and Thread Safety
It might seem odd to talk about thread safety in the context of dispatch queues, but thread safety is still a relevant topic. Any time you are implementing concurrency in your application, there are a few things you should know:
Dispatch queues themselves are thread safe. In other words, you can submit tasks to a dispatch queue from any thread on the system without first taking a lock or synchronizing access to the queue.
Do not call the
dispatch_syncfunction from a task that is executing on the same queue that you pass to your function call. Doing so will deadlock the queue. If you need to dispatch to the current queue, do so asynchronously using thedispatch_asyncfunction.Avoid taking locks from the tasks you submit to a dispatch queue. Although it is safe to use locks from your tasks, when you acquire the lock, you risk blocking a serial queue entirely if that lock is unavailable. Similarly, for concurrent queues, waiting on a lock might prevent other tasks from executing instead. If you need to synchronize parts of your code, use a serial dispatch queue instead of a lock.
Although you can obtain information about the underlying thread running a task, it is better to avoid doing so. For more information about the compatibility of dispatch queues with threads, see Compatibility with POSIX Threads.
https://developer.apple.com/library/archive/documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html#//apple_ref/doc/uid/TP40008091-CH102-SW28
Dispatch Queues and Thread Safety的更多相关文章
- iOS 并行编程:GCD Dispatch Queues
1 简介 1.1 功能 Grand Central Dispatch(GCD)技术让任务并行排队执行,根据可用的处理资源,安排他们在任何可用的处理器核心上执行任务.任务可以是一个函数 ...
- 线程安全 Thread Safety Problem scala concurrency 并发
小结: 1.基于java并发模型 Scala concurrency is built on top of the Java concurrency model. 2. 将每个请求放入一个新的线程 T ...
- Replacing Threads with Dispatch Queues
Replacing Threads with Dispatch Queues To understand how you might replace threads with dispatch que ...
- Dispatch Queues 线程池
Dispatch Queues Dispatch queues are a C-based mechanism for executing custom tasks. A dispatch queue ...
- Thread Safety线程安全
Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分 如果disabled就选择nts(php_stomp-1.0.9-5.5-nts-vc11-x86.zi ...
- Effective Java 70 Document thread safety
Principle The presence of the synchronized modifier in a method declaration is an implementation det ...
- Java Concurrency In Practice -Chapter 2 Thread Safety
Writing thread-safe code is managing access to state and in particular to shared, mutable state. Obj ...
- Thread safety
https://en.wikipedia.org/wiki/Thread_safety Thread safety is a computer programming concept applicab ...
- 折返(Reentrancy)VS线程安全(Thread safety)
在Wiki上,折返例如,下面的定义(接) In computing, a computer program or subroutine is called reentrant if it can be ...
随机推荐
- ansible common modules
##Some common modules[cloud modules] [clustering modules] [command modules]command - executes a comm ...
- 清北学堂模拟赛d6t5 侦探游戏
分析:简化一下题意就是给任意两对点连一条权值为0的边,求出每次连边后最小生成树的权值和*2/(n - 1) * n. 每次求最小生成树肯定会爆炸,其实每次加边只是会对最小生成树上的一条边有影响,也就是 ...
- Linux下C++开发教程收集
http://blog.csdn.net/wangfengwf/article/category/1315687 http://wiki.jikexueyuan.com/list/c/(极客学院C++ ...
- python 执行环境
一些函数 执行其它非python程序 1 一些函数 callable callable()是一个布尔函数,确定一个对象是否可以通过函数操作符(())来调用.如果函数可调用便返回True,否则便是Fal ...
- (二)模板引擎之Velocity脚本基本的语法全
velocity velocity三种reference 变量:对java对象的一种字符串化表示,返回值调用了java的toString()方法的结果. 方法:调用的是对象的某个方法. ...
- T470 Win10下触摸板手势
T470 Win10下触摸板手势 学习了:https://forum.51nb.com/thread-1742490-1-1.html 三指横向竟然是alt+tab 学习了:http://www.xi ...
- 设计模式实例(Lua)笔记之五(Bridge模式)
1.描写叙述 今天我要说说我自己,梦想中的我自己,我身价过亿,有两个大公司,一个是房地产公司,一个是服装制造业,这两个公司都非常赚钱,天天帮我在累加財富,事实上是什么公司我倒是不关心,我关心的是是不是 ...
- @Validated数据校验
//lastName必须是邮箱格式 @Email private String lastName;
- 小白学开发(iOS)OC_ 字符串写入文件(2015-08-13)
// // main.m // 字符串写入文件 // // Created by admin on 15/8/13. // Copyright (c) 2015年 admin. All rig ...
- Git Stash方法
命令:git stash1.使用git stash 保存当前的工作现场, 那么就可以切换到其他分支进行工作,或者在当前分支上完成其他紧急的工作,比如修订一个bug测试提交. 2.如果一个使用了一个gi ...