helloB
helloB

Reputation: 3582

In Objective-C where is code executed when I haven't specified a thread anywhere in my app?

I notice that I see behavior indicative of multi-threading even when I never explicitly use GCD or any other mechanisms to do things off the main thread. Why does this happen and what can I know or guess about my program behavior in cases where only some of my statements give directions about what thread should be used? Where should I have read about this that I haven't seen it?

Upvotes: 0

Views: 40

Answers (1)

Chris Trahey
Chris Trahey

Reputation: 18290

By default (if you don't use any concurrency APIs), almost all of your code will run on the main thread. This thread is managed by a run loop, the understanding of which may be a big part of what you're looking for.

The exceptions are documented on a case-by-case basis in Apple's documentation, and in order to get good information on SO about them, I would suggest posting a specific example of your code, what you expect, and what you specifically observe that has you thinking that it's happening on a different thread. As an FYI, you can see what thread your code is running on when you pause on a breakpoint, in the Navigator panel's Debug pane.

Upvotes: 3

Related Questions