<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>mikeash.com pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html comments</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>mikeash.com Recent Comments</description><lastBuildDate>Sun, 12 Apr 2026 03:38:39 GMT</lastBuildDate><generator>PyRSS2Gen-1.0.0</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>jjt - 2017-01-02 20:41:08</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>@bbum NSDictionary, the read-only version of NSMutableDictionary, is listed as Thread-Safe.</description><guid isPermaLink="true">4cd8a944c8ded4901f5b73518c05101c</guid><pubDate>Mon, 02 Jan 2017 20:41:08 GMT</pubDate></item><item><title>James Alan Bush - 2016-09-06 16:48:59</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Terrific post! Very concise, accurate. One question, though: how would one construct a CMSampleBuffer from a dispatch_data_t object?
&lt;br /&gt;
&lt;br /&gt;That's a big one, I know; but, it would solve a big problem for those needing to read assets (videos) without using AVFoundation...</description><guid isPermaLink="true">de3c0457e678929a1a7ceca03f9d1517</guid><pubDate>Tue, 06 Sep 2016 16:48:59 GMT</pubDate></item><item><title>Valeriy Van - 2016-05-10 12:47:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Description of &lt;code&gt;dispatch_data_apply&lt;/code&gt; doesn't give guarantee applier  block will not be fired concurrently. In that case &lt;code&gt;StringFromDispatchData&lt;/code&gt; function will crash.</description><guid isPermaLink="true">c1334ed70198298d90364621e1314a4d</guid><pubDate>Tue, 10 May 2016 12:47:23 GMT</pubDate></item><item><title>bbum - 2016-03-07 18:36:54</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Mike--
&lt;br /&gt;
&lt;br /&gt;The collection class documentation does not make any claims as to the thread safety of NSMutableDictionary in a read-only role.
&lt;br /&gt;
&lt;br /&gt;&lt;a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html"&gt;https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html&lt;/a&gt;</description><guid isPermaLink="true">9f36983f486040a0d714ffaa3d49184a</guid><pubDate>Mon, 07 Mar 2016 18:36:54 GMT</pubDate></item><item><title>jasna - 2015-05-23 20:43:39</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>well, it's way late but replying to don fulano: 
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogcommentquote"&gt;&lt;div class="blogcommentquoteinner"&gt;I am little unclear why the write block is dispatch_barrier_async and not a dispatch_barrier_sync. Don't you need it to be sync to make sure the data is finished writing before returning from the block. Won't the async return before the block is completed.&lt;/div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;assuming this is about thread-safe cache code above, you can afford to do async and return immediately, because all your getters are protected by dispatch_sync on the same dispatch queue; so your getter will block until earlier dispatch_barrier_async operation completes</description><guid isPermaLink="true">b6a0ac4c3b36019a739a1e6b6e0e7c2a</guid><pubDate>Sat, 23 May 2015 20:43:39 GMT</pubDate></item><item><title>HS - 2014-02-07 09:19:30</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>@mikeash: I was wondering how you get such type of information. You are an amazingly genius!</description><guid isPermaLink="true">91d4e77002793b7e9124d1c82c9bbb13</guid><pubDate>Fri, 07 Feb 2014 09:19:30 GMT</pubDate></item><item><title>roshni - 2013-11-14 12:41:40</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>@mikeash I am bit confuse when exactly to use sync and async,Can you elaborate on the same . thanks </description><guid isPermaLink="true">a9474db4d1c8cecfa434f36ebc605e3c</guid><pubDate>Thu, 14 Nov 2013 12:41:40 GMT</pubDate></item><item><title>tikhop - 2012-08-21 09:18:42</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>@mikeash become much clearer, thanks for the answer!
&lt;br /&gt;
&lt;br /&gt;I also had another test and it showed a lot more interesting: GCD 2x time faster.
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://stackoverflow.com/questions/11920584/mutating-array-while-reading-not-enumerating/11921122#11921122"&gt;http://stackoverflow.com/questions/11920584/mutating-array-while-reading-not-enumerating/11921122#11921122&lt;/a&gt;</description><guid isPermaLink="true">ab53941f3fea9f76db0e593d69758ca4</guid><pubDate>Tue, 21 Aug 2012 09:18:42 GMT</pubDate></item><item><title>mikeash - 2012-08-13 18:14:06</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>&lt;b&gt;tikhop:&lt;/b&gt; The semantics are quite different. A custom concurrent queue using barriers will allow multiple active readers simultaneously, or one writer, while @synchronized only ever allows a single thread to be within the synchronized block at a time (with the same lock object). Additionally, using a dispatch queue means that your locked operations can be run asynchronously, whereas code must always wait for a @synchronized block to complete before continuing. There's nothing wrong with @synchronized, and if it fits your needs then by all means use it.
&lt;br /&gt;
&lt;br /&gt;&lt;b&gt;Andrew:&lt;/b&gt; I don't understand the relevance of posting the declaration for &lt;code&gt;dispatch_get_global_queue&lt;/code&gt;. In any case, the documentation is quite clear that the &lt;code&gt;dispatch_barrier_async&lt;/code&gt; function and its friends are available on 10.7+ and 4.3+.</description><guid isPermaLink="true">e1d18a7b427024bc6523bdba9a5b45ea</guid><pubDate>Mon, 13 Aug 2012 18:14:06 GMT</pubDate></item><item><title>Andrew - 2012-08-13 12:45:57</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>This gentleman on stackoverflow has posted the header files for some of these APIs which suggest that these tools were actually available in iOS 4, not iOS 5. i'm a little confused so any assistance is appreciate; many resources around the web suggest only Lion and iOS 5 feature some of these options:
&lt;br /&gt;
&lt;br /&gt;&lt;a href="http://stackoverflow.com/a/11926625/768472"&gt;http://stackoverflow.com/a/11926625/768472&lt;/a&gt;</description><guid isPermaLink="true">06b3a7d8ee4102914389297774211ac1</guid><pubDate>Mon, 13 Aug 2012 12:45:57 GMT</pubDate></item><item><title>tikhop - 2012-08-12 11:10:22</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Why I should use dispatch_barrier_async instead of @synchronized. I try both approach and @synchronized method little bit faster.</description><guid isPermaLink="true">a3096f6c1dfaefac72d45aed0f1ad342</guid><pubDate>Sun, 12 Aug 2012 11:10:22 GMT</pubDate></item><item><title>mikeash - 2012-04-04 14:31:08</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>It doesn't matter if the data isn't written before the method completes. The only way to retrieve data from the cache is to use the dispatch queue, which will wait until all previous writes are complete.</description><guid isPermaLink="true">465c2d2d56f4e20cc3fbc04bfd5b7c6e</guid><pubDate>Wed, 04 Apr 2012 14:31:08 GMT</pubDate></item><item><title>Don Fulano - 2012-04-04 03:48:59</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>I am little unclear why the write block is dispatch_barrier_async and not a dispatch_barrier_sync.  Don't you need it to be sync to make sure the data is finished writing before returning from the block.  Won't the async return before the block is completed.</description><guid isPermaLink="true">056c000c51d17301023a994449046c71</guid><pubDate>Wed, 04 Apr 2012 03:48:59 GMT</pubDate></item><item><title>David H - 2011-11-16 15:21:37</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Your information on "concurrent queue and barriers" is just EXCELLENT and a huge help to me (who is using gobs of operations and async dispatches on an iPhone app.
&lt;br /&gt;
&lt;br /&gt;Note that DISPATCH_QUEUE_PRIORITY_BACKGROUND is also available on iOS 4.
&lt;br /&gt;
&lt;br /&gt;David</description><guid isPermaLink="true">1dc8b1f7cebc431494b3cbe4e101d579</guid><pubDate>Wed, 16 Nov 2011 15:21:37 GMT</pubDate></item><item><title>mikeash - 2011-10-19 17:59:43</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Under ARC you need to explicitly reference the data object in the block in some other way, like &lt;code&gt;[nsdata self]&lt;/code&gt;. It makes no difference at all whether the captured variable is decorated with &lt;code&gt;__block&lt;/code&gt; or not.</description><guid isPermaLink="true">d2a1c2533deb1b974c96547f8746128b</guid><pubDate>Wed, 19 Oct 2011 17:59:43 GMT</pubDate></item><item><title>Jean-Daniel - 2011-10-19 17:22:24</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>To follow up Tom suggestion, using __block has an other big advantage, it works with ARC, where explicit release call is prohibited.
&lt;br /&gt;</description><guid isPermaLink="true">66e2862793f4293639c6d62a069d4349</guid><pubDate>Wed, 19 Oct 2011 17:22:24 GMT</pubDate></item><item><title>mikeash - 2011-10-18 14:30:18</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Makes sense, it's going to be pretty fast either way.</description><guid isPermaLink="true">0d2c5f88dfbdd682e3dd81805dc221e5</guid><pubDate>Tue, 18 Oct 2011 14:30:18 GMT</pubDate></item><item><title>Tom M - 2011-10-18 07:37:19</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>It was more an observation, and as you say, it would be foolish to assume which is faster. You got me curious enough to have a quick look, and as it happens it seems to be a wash. Certainly for &lt;code&gt;NSData&lt;/code&gt; objects (of the size I was testing, which were pretty small) the difference wasn't statistically different. On multiple runs, it went either way. A quick look with Instruments shows that it's just not spending enough time in the block copy helper to be meaningful compared to other big ticket items (like &lt;code&gt;objc_msgSend&lt;/code&gt;, and memory operations).</description><guid isPermaLink="true">1f52372b7ceef251ed4359657799b9e2</guid><pubDate>Tue, 18 Oct 2011 07:37:19 GMT</pubDate></item><item><title>Steven Fusco - 2011-10-17 18:10:36</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>You can get to priority background and the new barrier API in iOS 4.3, no need to wait for 5.  It's marked __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_3)
&lt;br /&gt;&amp;nbsp;in the header</description><guid isPermaLink="true">e29dc5ed1597e5a18dc7530ed7d046e1</guid><pubDate>Mon, 17 Oct 2011 18:10:36 GMT</pubDate></item><item><title>mikeash - 2011-10-16 04:01:23</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>True, but it's not a problem. Are you suggesting that using __block will be faster? I'd want to see measurements on that before accepting it if that's the case, since __block captured variables have additional overhead compared to the regular kind.</description><guid isPermaLink="true">a69862d75bb2946485805042b2343c0a</guid><pubDate>Sun, 16 Oct 2011 04:01:23 GMT</pubDate></item><item><title>Tom M - 2011-10-16 02:22:24</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>Great summary of the new GCD features.
&lt;br /&gt;
&lt;br /&gt;One minor point: block capture in &lt;code&gt;CreateDispatchDataFromNSData&lt;/code&gt; will result in a redundant retain/release taking place for the copied &lt;code&gt;nsdata&lt;/code&gt;. Storing the copy in a &lt;code&gt;__block  NSData*&lt;/code&gt; auto variable would eliminate that.</description><guid isPermaLink="true">8f6cdc1b5c184ca7abbe89c495b07833</guid><pubDate>Sun, 16 Oct 2011 02:22:24 GMT</pubDate></item><item><title>mikeash - 2011-10-14 21:56:41</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>The trouble with thread-safe (note, not reentrant, subtle difference) containers is that they're difficult to create, tend to be slow, and leave their users open to nasty threading bugs &lt;i&gt;anyway&lt;/i&gt;.
&lt;br /&gt;
&lt;br /&gt;For example, you might write a method to getthe first item of an array:
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;- (id)firstItem { return [array count] ? [array objectAtIndex: 0] : nil; }&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;However, with an array being used by multiple threads, this code is unsafe even if the array itself is nominally thread safe, because another thread could remove the last object from the array between the check and the fetch.
&lt;br /&gt;
&lt;br /&gt;Fundamentally, thread safety doesn't compose. It's painful, but there we are.
&lt;br /&gt;
&lt;br /&gt;What you'd really need is something that allowed for transactions on these containers, which would be really useful but fairly complex, or something which allowed locking around multiple operations which need to be atomic, which works but basically puts you right back to square one.</description><guid isPermaLink="true">8419b9ba68f48766a3c0059e0e1f9ed3</guid><pubDate>Fri, 14 Oct 2011 21:56:41 GMT</pubDate></item><item><title>Brent Gulanowski - 2011-10-14 13:36:53</title><link>http://www.mikeash.com/?page=pyblog/friday-qa-2011-10-14-whats-new-in-gcd.html#comments</link><description>So, when do we get foundation containers and file abstractions that have (optional) integrated support for re-entrancy based on this? Seems like a no-brainer to encapsulate the custom dispatch queue right into the object. Until then, I guess we use custom wrappers. (NSMutableDictionary&amp;lt;-(NS)ReentrantDictionary?)</description><guid isPermaLink="true">5a5e830b6f57c40a14d02b124d4dc0c6</guid><pubDate>Fri, 14 Oct 2011 13:36:53 GMT</pubDate></item></channel></rss>
