Dispatch_async()和类似方法是否提供内存隔离墙? [英] Does dispatch_async() and similar provide memory fences?

查看:68
本文介绍了Dispatch_async()和类似方法是否提供内存隔离墙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我通过dispatch_async或类似方法在任何队列上运行一个块时,GCD是否在块调用周围提供线程防护?我以为可以,但是据我所知,文档没有给出任何一种提示.

When I run a block on any queue via dispatch_async or similar, does GCD provide thread fences around the block invocation? I would assume it does, but the documentation gives no hint one way or the other as far as I can tell.

推荐答案

在Cocoa-Dev邮件列表中的电子邮件线程中,格雷格·帕克(Apple的运行时工程师)

From an email thread on the Cocoa-Dev mailing list, Greg Parker (one of Apple's runtime engineers) replied to a question of mine:

[S]因为使用GCD并没有给我们所有人带来灾难,所以我认为dispatch_async()等确实提供了此类内存障碍.同样,NSOperationQueue,-performSelector:onThread:...等也必须.是吗?

[S]ince the use of GCD hasn't brought catastrophe down on all of our heads, I assume that dispatch_async() and the like do provide such memory barriers. Likewise, NSOperationQueue, -performSelector:onThread:..., and the like must also. Is that right?

我希望没有为某些用途提供足够内存障碍的任何多处理原语都会大声地记录这一事实. dispatch_once()的存储是缺少障碍的一个有据可查的示例.某些OSAtomic功能是另一个示例.但是,几乎所有比这重的东西都应该为任何客户端提供完整的内存屏障.

I would expect that any multiprocessing primitive that does not provide sufficient memory barriers for some uses would document that fact loudly. dispatch_once()'s storage is one documented example of missing barriers. Some of the OSAtomic functions are another example. But pretty much everything heavier-weight than that ought to provide complete memory barriers for any clients.

这篇关于Dispatch_async()和类似方法是否提供内存隔离墙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆