Grand Central Dispatch Dispatch Dispatch
Work dispatch_block_t or dispatch_function_t dispatch_queue_t dispatch_source_t dispatch_group_t Queue
^ { for ( int  i =  0 ; i < something very large; i++) { do_heavy_work(); and_keep_doing_it(); } } dispatch_async (..., );
dispatch_async_f(..., ); function foo(void *context) { for ( int  i =  0 ; i < something very large; i++) { do_heavy_work(...
^ { for ( int  i =  0 ; i < something very large; i++) { do_heavy_work(); sum += and_keep_doing_it(); } } dispatch_sync (....
Main queue Global queues dispatch_get_main_queue () dispatch_get_global_queue ( X ,  0 ) DISPATCH_QUEUE_PRIORITY_LOW DISPA...
^ { for ( int  i =  0 ; i < something very large; i++) { do_heavy_work(); sum += and_keep_doing_it(); } } dispatch_async (...
^ { for ( int  i =  0 ; i < something very large; i++) { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_async ( d...
^ { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_queue_t global = dispatch_get_global_queue( 0 ,  0 ); dispatch...
^ { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_queue_t global = dispatch_get_global_queue( 0 ,  0 ); dispatch...
^ { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_queue_t global = dispatch_get_global_queue( 0 ,  0 ); dispatch...
<ul><li>void  dispatch_once( dispatch_once_t  *predicate,  dispatch_block_t  block); </li></ul><ul><li>void  dispatch_afte...
http://mikeash.com/?page=pyblog http://thirdcog.eu/pwcblocks/ http://thirdcog.eu/pwcblocks/ http://thirdcog.eu/pwcblocks/
Upcoming SlideShare
Loading in...5
×

Grand Central Dispatch

2,286

Published on

My talk on GCD at Cocoaheads Stockholm. Video of the talk: http://bambuser.com/channel/rasmus/broadcast/358572

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,286
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Grand Central Dispatch

  1. 1. Grand Central Dispatch Dispatch Dispatch
  2. 2. Work dispatch_block_t or dispatch_function_t dispatch_queue_t dispatch_source_t dispatch_group_t Queue
  3. 3. ^ { for ( int i = 0 ; i < something very large; i++) { do_heavy_work(); and_keep_doing_it(); } } dispatch_async (..., );
  4. 4. dispatch_async_f(..., ); function foo(void *context) { for ( int i = 0 ; i < something very large; i++) { do_heavy_work(); and_keep_doing_it(); } } NULL , &foo
  5. 5. ^ { for ( int i = 0 ; i < something very large; i++) { do_heavy_work(); sum += and_keep_doing_it(); } } dispatch_sync (..., ); __block int sum = 0 ; NSRunAlertPanel ( @&quot;Found the sum!&quot; , @&quot;It's: %d&quot; , @&quot;OK&quot; , nil , nil , sum);
  6. 6. Main queue Global queues dispatch_get_main_queue () dispatch_get_global_queue ( X , 0 ) DISPATCH_QUEUE_PRIORITY_LOW DISPATCH_QUEUE_PRIORITY_DEFAULT DISPATCH_QUEUE_PRIORITY_HIGH Custom queues dispatch_queue_create() serial concurrent serial
  7. 7. ^ { for ( int i = 0 ; i < something very large; i++) { do_heavy_work(); sum += and_keep_doing_it(); } } dispatch_async ( dispatch_get_global_queue ( 0 , 0 ) , ); __block int sum = 0 ; NSRunAlertPanel ( @&quot;Found the sum!&quot; , @&quot;It's: %d&quot; , @&quot;OK&quot; , nil , nil , sum);
  8. 8. ^ { for ( int i = 0 ; i < something very large; i++) { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_async ( dispatch_get_main_queue () , ); } dispatch_async ( dispatch_get_global_queue ( 0 , 0 ) , ); __block int sum = 0 ; ^ { NSRunAlertPanel ( @&quot;Found the sum!&quot; , @&quot;It's: %d&quot; , @&quot;OK&quot; , nil , nil , sum); }
  9. 9. ^ { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_queue_t global = dispatch_get_global_queue( 0 , 0 ); dispatch_apply (something very large, global, ); __block int sum = 0 ; NSRunAlertPanel ( @&quot;Found the sum!&quot; , @&quot;It's: %d&quot; , @&quot;OK&quot; , nil , nil , sum );
  10. 10. ^ { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_queue_t global = dispatch_get_global_queue( 0 , 0 ); dispatch_apply (something very large, global, ); __block int sum = 0 ; NSRunAlertPanel ( @&quot;Found the sum!&quot; , @&quot;It's: %d&quot; , @&quot;OK&quot; , nil , nil , sum );
  11. 11. ^ { do_heavy_work(); sum += and_keep_doing_it(); } dispatch_queue_t global = dispatch_get_global_queue( 0 , 0 ); dispatch_group_t group = dispatch_group_create (); for ( int i = 0 ; i < something very large; i++) { dispatch_group_async (group, queue, ); } __block int sum = 0 ; dispatch_group_notify (group, queue, ); dispatch_release (group); NSRunAlertPanel ( @&quot;Found the sum!&quot; , @&quot;It's: %d&quot; , @&quot;OK&quot; , nil , nil , sum );
  12. 12. <ul><li>void dispatch_once( dispatch_once_t *predicate, dispatch_block_t block); </li></ul><ul><li>void dispatch_after( dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block); </li></ul><ul><li>void dispatch_main( void ); </li></ul><ul><li>void dispatch_set_target_queue( dispatch_object_t object, dispatch_queue_t queue); </li></ul><ul><li>dispatch_retain/dispatch_release </li></ul><ul><li>dispatch_get_context/dispatch_set_context/dispatch_set_finalizer_f </li></ul><ul><li>dispatch_suspend/dispatch_resume </li></ul><ul><li>dispatch_semaphore_create </li></ul>
  13. 13. http://mikeash.com/?page=pyblog http://thirdcog.eu/pwcblocks/ http://thirdcog.eu/pwcblocks/ http://thirdcog.eu/pwcblocks/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×