- 浏览: 569820 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
JYY282:
[i][/i]
Ecshop与Shopex的比较 -
qq247890212:
我也遇见这问题了,真诡异。重新下载个猫换了就好了。 太浪费时间 ...
诡异:ClassNotFoundException: org.springframework.web.filter.CharacterEncoding
GCD 概述
1. GCD 包含于 libSystem.dylib
2. 可供所有程序使用.
- #include <dispatch/dispatch.h>
3. GCD API 提供 block-based and function-based variants
- 目前仅提供 block-based API
GCD总结
1. Blocks
- dispatch_async()
2. Queues
- Lightweight list of blocks
- Enqueue/dequeue is FIFO
3. dispatch_get_main_queue()
- Main thread/main runloop
4. dispatch_queue_create()
- Automatic helper thread
GCD的好处
1. 高效 - More CPU cycles available for your code
2. 使用方便
- Blocks are easy to use
- Queues are inherently producer/consumer
3. Systemwide perspective
- Only the OS can balance unrelated subsystems
兼容性
1. Existing threading and synchronization primitives are 100% compatible
2. GCD threads are wrapped POSIX threads
- Do not cancel, exit, kill, join, or detach GCD threads
3. GCD reuses threads
- Restore any per-thread state changed within a block
多线程
Session 206已提到此内容。
锁定资源
1. 对关键资源进行互斥访问。
2. 在线程中按序访问共享资源。
3. Ensure data integrity
没有GCD的代码
- (void)updateImageCacheWithImg:(UIImage*)img {
NSLock *l = self.imageCacheLock;
[l lock];
// Critical section
if ([self.imageCache containsObj:img]) {
[l unlock]; // Don't forget to unlock
return;
}
[self.imageCache addObj:img];
[l unlock];
}
GCD代码
- (void)updateImageCacheWithImg:(NSImage*)img {
dispatch_queue_t queue = self.imageCacheQueue;
dispatch_sync(queue, ^{ //You can change dispatch_sync to dispatch_async to defer critical section
// Critical section
if ([self.imageCache containsObj:img]) {
return;
}
[self.imageCache addObj:img];
});
}
线程间通信
通过以下方法 (Without GCD)
– performSelectorOnMainThread:withObject:waitUntilDone:
– performSelector:onThread:withObject:waitUntilDone:
– performSelector:withObject:afterDelay:
– performSelectorInBackground:withObject:
GCD 代码,等同于 performSelector:onThread:withObject:waitUntilDone:
// waitUntilDone: NO
dispatch_async(queue, ^{
[myObject doSomething:foo withData:bar];
});
// waitUntilDone: YES
dispatch_sync(queue, ^{
[myObject doSomething:foo withData:bar];
});
GCD代码, 等同于 performSelector:withObject:afterDelay:dispatch_time_t delay;delay = dispatch_time(DISPATCH_TIME_NOW, 50000 /* 50μs */);dispatch_after(delay, queue, ^{ [myObject doSomething:foo withData:bar];});GCD代码,等同于 performSelectorInBackground:withObject:dispatch_queue_t queue = dispatch_get_global_queue(0, 0);dispatch_async(queue, ^{ [myObject doSomething:foo withData:bar];});
Global Queues1. Enqueue/dequeue is FIFO
2. Concurrent execution- Non-FIFO completion order
3. dispatch_get_global_queue(priority, 0)
4. Global queues map GCD activity to real threads 5. Priority bands- DISPATCH_QUEUE_PRIORITY_HIGH - DISPATCH_QUEUE_PRIORITY_DEFAULT - DISPATCH_QUEUE_PRIORITY_LOW
下面三节讲述了很多内容,但我还没有理解。如有兴趣,请看原始视频。- Dispatch Sources
- Source Cancellation- Target Queues
GCD对象
GCD方法大全
管理对象的生命周期
1. Ensure objects captured by blocks are valid when blocks are executed
- Objects must be retained and released around asynchronous operations
2. Objective-C objects captured by blocks are auto-retained and auto-released
3. Other objects captured by blocks must be retained by your code
- CFRetain()/CFRelease()
- dispatch_retain()/dispatch_release()
挂起和恢复
1. Suspend and resume only affects queues and sources you create
- Sources are created suspended
2. Suspension is asynchronous
- Takes effect between blocks
3. Your queues can predictably suspend objects that target them
程序上下文
1. Applications can attach custom data to GCD objects
- dispatch_set_context()/dispatch_get_context()
2. Optional finalizer callback
- dispatch_set_finalizer_f()
- Allows attached context to be freed with object
- Called on the target queue of the object
WWDC2010 Session211 Simplifying iPhone App Development with Grand Central Dispatch
Daniel Steffen - Core OS
发表评论
-
Objective-C 与 C++ 的异同
2013-04-02 12:03 1358http://www.cnblogs.com/y041039 ... -
Cocos2D-X是全球知名的开源跨平台手机游戏引擎
2013-01-22 10:05 2710http://www.oschina.net/p/cocos ... -
iOS Keyboard 键盘高度变化 自适应
2013-01-15 15:43 3219[[NSNotificationCenter default ... -
iOS使用自定义字体
2012-11-27 12:11 12077From: http://blog.csdn.net/csy1 ... -
4 款类似 Facebook/Path 切换效果的 iOS 组件
2012-11-27 12:03 2091From: http://blog.csdn.net/lia ... -
Path 2.0的UI界面设计详细介绍
2012-11-27 11:56 1426如Path的创始人Dave Morin ... -
史上最全的App Store邮箱列表
2012-11-27 11:51 1219From: http://roybaby.blog.51cto ... -
iOS从info.plist 获取项目的名称及版本号
2012-11-16 10:54 1575From: http://blog.sina.com.cn/s ... -
MapKit annotation drag and drop with callout info update
2012-10-13 10:38 2363http://hollowout.blogspot ... -
NSArray 或NSDictionary 调用writeToFile方法失败原因
2012-08-31 10:03 4422NSArray 或NSDictionary 调用writeTo ... -
如何让IOS应用从容地崩溃
2012-08-30 15:25 1571From: http://www.cocoachina.com ... -
iOS中判断设备系统版本
2012-08-29 17:17 31669在iOS开发中,经常要考虑系统的向下兼容,如果使用 ... -
iOS 汉字转拼音
2012-08-21 16:42 1424From: http://www.cnblogs.com/v2 ... -
iOS模拟器截图工具
2012-08-17 16:35 1583From: http://magicalboy.com/ios ... -
XCode下的iOS单元测试
2012-08-10 17:47 1120From: http://mobile.51cto.com/ ... -
AFNetworking
2012-08-08 10:54 4622AFNetworking on github: https:/ ... -
Wrapping Conventions
2012-08-01 15:54 779Wrapping Conventions ... -
Core Animation如何使显式动画结束时的值直接作用Layer
2012-08-01 14:51 3747(1)使用隐式动画会直接改变layer的属性值,如: ima ... -
How To Debug Memory Leaks with XCode and Instruments Tutoria
2012-07-31 16:30 1019From: http://www.raywenderlich. ... -
Using Properties in Objective-C Tutorial
2012-07-31 16:27 879From: http://www.raywenderlich. ...
相关推荐
pytorch-grad-cam源代码阅读和调试
grad-cam Pytorch实现,类激活图,可视化feature map,热图显示图像分类的分类原因,因为什么分的类。
Grad-CAM(Gradient-weighted Class Activation Mapping)是一种可视化网络中哪些区域对分类结果有更大的贡献的方法,它能够在图像分类任务中帮助我们理解神经网络是如何作出决策的。Grad-CAM 通过利用深度卷积神经...
刘彬20000词汇思维导图
我们调查了可解释性问题 视觉对象检测器。...YOLO对象检测器的示例 如何将GradCAM集成到模型架构中并分析结果。 我们将展示如何计算基于归因的解释 个别检测并发现 结果对它们的解释有很大的影响。
Grad-CAM-张量流 注意:CNN还有另一种很棒的可视化方法,称为 ,它仅涉及前向通过。 演示代码可用于Caffe和Tensorflow ResNet,Vgg。 请检查一下。 这是用于Grad-CAM的演示的tensorflow版本。 我使用ResNet-v1-101...
pytorch实现Grad-CAM和Grad-CAM++,可以可视化任意分类网络的Class Activation Map (CAM)图,包括自定义的网络;同时也实现了目标检测faster r-cnn和retinanet两个网络的CAM图; 使用方法 python main.py --image-path ...
纯代码布局,MVC设计模式。数据神马的,自己去搞吧。我写了一个本地的plist文件,运行即可看出数据结构。都是按照接口的样式写的,如果需求也是这样的小伙伴,加上数据解析,代码直接就可以用!...
optical lithography pst-grad,optical lithography pst-grad
在Pytorch中实现Grad-CAM 是什么使网络认为图像标签是“ pug,pug-dog”和“ tabby,虎斑猫”: 将Grad-CAM与引导反向传播相结合的“ pug,pug-dog”类别: 梯度类激活图是用于深度学习网络的可视化技术。 参见...
Swin-Transformer+gradcam可视化代码+Windows环境
pytorch-Grad-CAM-热度图制作掩膜-对原图进行剪裁
Grad-CAM.pytorch pytorch 实现 和 3.1 3.3 5.1 5.2 5.3 5.4 6.1 6.2 6.3 6.4 7.1 7.2 7.3 7.4 Grad-CAM整体架构 Grad-CAM++与Grad-CAM的异同 依赖 python 3.6.x pytoch 1.0.1+ torchvision 0.2.2 ...
Grad-CAM的Pytorch实现。Pytorch implementation of Grad-CAM
它允许使用多种方法(例如,反向引导传播,Grad-Cam,Guide Grad-Cam和Grad-Cam ++)生成注意力图。 您需要添加到项目中的只是一行代码: model = gcam . inject ( model , output_dir = "attention_maps" , save_...
在Keras中实现Grad-CAM 梯度类激活图是用于深度学习网络的可视化技术。 参见论文: : 该论文的作者实现了火炬实施: : 该代码假定Tensorflow尺寸顺序,并默认在keras.applications中使用VGG16网络(网络权重将在...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
Grad-CAM的Pytorch实现。Pytorch implementation of Grad-CAM
Pytorch中的Grad-CAM实现使网络认为图像标签是“ pug,pug-dog”和“ tabby,虎斑猫”的原因:针对“ pug,pug-dog”类将Grad-CAM与引导反向传播结合起来:Gra Grad -Pytorch中的-CAM实施使网络认为图像标签是“ pug...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装