• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: GCD question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCD question


  • Subject: Re: GCD question
  • From: Jonathan Taylor <email@hidden>
  • Date: Thu, 19 Jul 2012 13:31:41 +0100

> If I use this to initiate a background "thread":
>
>
> dispatch_async(dispatch_get_global_queue(0, 0), ^{
>
> // do some stuff
>
> [self runMyFunction];
>
> [self runAnotherFunction];
>
> // do some more stuff
>
> });
>
>
> My question is with my sample calling runMyFunction or runAnotherFunction are they blocking?  Meaning will they block the background "thread" until they are complete and then it will continue?  Or must I put them into another kind of block so that they finish FIFO?  Thanks just looking for a confirmation as I'm moving to GCD from threads...

You are correct in that they are "blocking" if I understand you correctly. There is nothing magic about the concept of GCD blocks, they are really just anonymous functions with a slightly unusual scope. You would be equally welcome to use the alternative dispatch_async_f API, which would have exactly the same outcome (code written in Mail; not complied!):

void MyDispatchFunc(void *)
{
	// do some stuff
	[self runMyFunction];
	[self runAnotherFunction];
	// do some more stuff
}

void foo(void)
{
	dispatch_async_f(dispatch_get_global_queue(0, 0), MyDispatchFunc);
}


I hope it is obvious from this alternative formulation that there is nothing "magic" going on: the API call is just scheduling a call to MyDispatchFunc at the time GCD deems appropriate. Exactly the same is true of the example you gave, it is just that you are passing a block around instead of a function pointer.

Hope that helps
Jonny
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: 10.7 Full-Screen transition animation corrupts my UI - how to avoid?
  • Next by Date: Re: KVC generic enough?
  • Previous by thread: Re: GCD question
  • Next by thread: Sharing a file between Mac and iOS
  • Index(es):
    • Date
    • Thread