the_mandrill
the_mandrill

Reputation: 30862

Catching thread exit in Xcode

I'm trying to resolve a very nasty Heisenbug under Xcode where I have a thread that's doing some background processing by calling into an external library, and at some point it appears that the thread is just disappearing. The code is something like this:

LOG("starting operation");
float progress=0;
while (progress < 1.0f) {
  LOG("start loop");
  Wait(100); // calls ::Delay()
  progress=otherLibrary->CheckProgress();
  LOG("end loop");
}

In my log file I get output similar to this:

starting operation
start loop
end loop
starting operation
start loop

It appears that the loop is just bombing out somehow. It isn't hanging, as if I break into the debugger, that thread doesn't appear to exist any more. If I add more logging or move functions around it goes wrong in slightly different places. In some cases it even seems to bomb out inside the system's Delay() function.

The question is: how can I detect the point at which this thread is aborting?

There are no exceptions being thrown, nothing in the Console (gdb or system). GDB handily tells me that Catch of thread_exit not yet implemented. The debug build doesn't reproduce this behaviour (oh joy), and neither does my minimal test app. I've removed the logging code in case this is causing some strange synchronisation effects, but that doesn't help.

Upvotes: 1

Views: 970

Answers (1)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81878

Set a breakpoint in _pthread_exit.

  1. In Xcodes's menu select "Run" —> "Show" —> "Breakpoints"
  2. Double click on the last line in the breakpoints table.
  3. Enter "_pthread_exit".

You might also want to set a breakpoint in pthread_cancel.

Upvotes: 4

Related Questions