<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Mon, 17 Aug 2026 11:44:51 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Pitiphong Phongpattranont - 2013-09-20 11:24:10</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>FYI &lt;a href="https://devforums.apple.com/message/893877#893877"&gt;https://devforums.apple.com/message/893877#893877&lt;/a&gt;</description><guid isPermaLink="true">896ede6c1b1e9ddb288def086f537a4f</guid><pubDate>Fri, 20 Sep 2013 11:24:10 GMT</pubDate></item><item><title>Pitiphong Phongpattranont - 2013-09-18 15:13:18</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>I'm curious about dispatch_barrier and the target queue. What happen when I dispatch_barrier blocks on the queue that targeted on the concurrent queue? Will I block the execution of the blocks submitted to the targeted queue too? Or if I dispatch_barrier blocks to the concurrent queue, will it block the execution of the blocks in the child queue?</description><guid isPermaLink="true">34fd25eb18e0a703c561927e078aecbc</guid><pubDate>Wed, 18 Sep 2013 15:13:18 GMT</pubDate></item><item><title>mikeash - 2009-09-21 02:30:37</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>The first two do not. They are documented as setting up a timer in the current runloop, which GCD can't currently do. Until and unless GCD becomes the foundation for CFRunLoop, these won't involve GCD.
&lt;br /&gt;
&lt;br /&gt;The last one almost could, except that it's documented as creating a new thread. Code using that method could expect that they own the thread that their code executes on and might do things that GCD doesn't like (you're not allowed to do things like mess with your thread's priority, kill the thread, etc. while executing on a GCD thread) so Apple couldn't really change that one either.</description><guid isPermaLink="true">96b55dca1f80699cb96bd7c207c32c0c</guid><pubDate>Mon, 21 Sep 2009 02:30:37 GMT</pubDate></item><item><title>Christophe Braud - 2009-09-21 02:01:00</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>With NSObject we have some functions like 
&lt;br /&gt;
&lt;br /&gt;- performSelector:withObject:afterDelay
&lt;br /&gt;- performSelector:withObject:afterDelay:inModes
&lt;br /&gt;- performSelectorInBackground
&lt;br /&gt;...
&lt;br /&gt;
&lt;br /&gt;these functions are implemented with GCD too?</description><guid isPermaLink="true">734a89e94c9ad6ae494fd1142db7ba9d</guid><pubDate>Mon, 21 Sep 2009 02:01:00 GMT</pubDate></item><item><title>mikeash - 2009-09-19 00:18:58</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>&lt;b&gt;Axel Andersson:&lt;/b&gt; A fine question, and one I asked myself as well when I saw that macro. You'll find the answer to that question in a comment in the source code which implements the one-time initialization functionality:
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://libdispatch.macosforge.org/trac/browser/trunk/src/once.c"&gt;http://libdispatch.macosforge.org/trac/browser/trunk/src/once.c&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;Scroll down to where it reads "The next barrier must be long and strong" and go from there.
&lt;br /&gt;
&lt;br /&gt;The summary is that raw double-checked locking has problems because you need memory barriers to make sure all threads see changes happen in the right order. Normally you need both read and write barriers. What the dispatch guys figured out was that you don't need read barriers if the write side ensures that enough cycles occur between the initialization and the signal that it's impossible for any reader to have performed an out-of-order read that sees the one but not the other.
&lt;br /&gt;
&lt;br /&gt;In other words, modern CPUs perform out-of-order reads only in close temporal proximity. By waiting a few cycles before writing to the shared flag, they ensure that any CPU which sees the shared flag as being set will also have seen all initialization take place. This allows them to get away with only a write barrier, and no read barrier.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Stuart Dootson:&lt;/b&gt; Blocks don't work on previous versions of OS X by default, because they need a runtime library. It's not substantial, but it is required. Don't let C++0x lambdas trick you; Apple's blocks are a lot more capable in ways that require additional runtime support. (Namely, they can persist beyond the scope that created them, and they need to manage memory in order to make that happen.)
&lt;br /&gt;
&lt;br /&gt;There is a third-party blocks runtime (built using Apple's source code) and associated compilers available called PLBlocks. More details on that here:
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://www.mikeash.com/?page=pyblog/friday-qa-2009-08-14-practical-blocks.html"&gt;http://www.mikeash.com/?page=pyblog/friday-qa-2009-08-14-practical-blocks.html&lt;/a&gt;</description><guid isPermaLink="true">cc4b4191904a2866cbf4c894b87fc522</guid><pubDate>Sat, 19 Sep 2009 00:18:58 GMT</pubDate></item><item><title>Stuart Dootson - 2009-09-19 00:05:35</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>Mike - a question about blocks (kind of tangential, as this series, which has been very informative, has been about GCD, but GCD does use blocks extensively…):
&lt;br /&gt;
&lt;br /&gt;If you know….
&lt;br /&gt;
&lt;br /&gt;Is code using blocks (not GCD, just blocks) runnable on previous versions of OS X? Is there a dependency on Snow Leopard's version of the C run-time or something?
&lt;br /&gt;
&lt;br /&gt;I'm wondering, because knowing how lambdas are implemented in C++0x (as function objects), it seems like blocks shouldn't require tooo much in the way of run-time support?</description><guid isPermaLink="true">58577f871c05a4af29369ed7953c38e4</guid><pubDate>Sat, 19 Sep 2009 00:05:35 GMT</pubDate></item><item><title>Axel Andersson - 2009-09-18 22:59:22</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2009-09-18-intro-to-grand-central-dispatch-part-iv-odds-and-ends.html#comments</link><description>For dispatch_once, I'm curious whether the use of an initial inline test constitutes double-checked locking, or if there are any protections against that.</description><guid isPermaLink="true">b75aa3efc5bf13463b745c7600612f7d</guid><pubDate>Fri, 18 Sep 2009 22:59:22 GMT</pubDate></item></channel></rss>
