Hi! We are seeing a bit surprising behavior of dispatch_main on macOS where it seems to spawn a different thread instead of preserving the one it gets called from.
Managed to reproduce it in a completely empty command-line tool project in Xcode
int main(int argc, const char * argv[]) {
@autoreleasepool {
dispatch_main();
return 0;
}
}
I put a breakpoint on the line with dispatch_main
and see that I am on Thread 1
and inside main function. That makes sense.
I resume execution and pause again. Looking at Thread
output in Xcode, I can only see Thread 2
.
Thread 1
is gone and the executable keeps on running.
So dispatch_main
did what was expected (prevented the process from termination) but throws out the thread it was called from and creates a new one? Is that behavior expected or am I missing something?
Just a brain teaser at this point. But we could not make sense out of it. :)
That’s right. See the explanation in this post.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"