Re: Threads - while debugging
Re: Threads - while debugging
- Subject: Re: Threads - while debugging
- From: James Bucanek <email@hidden>
- Date: Mon, 14 Nov 2005 08:19:08 -0700
John Draper wrote on Sunday, November 13, 2005:
>When I'm single stepping using the X-Code debugger, and I step
>through a method that creates the thread, then stop at the
>next instruction, will the thread execute or will it stop prior
>to execution. Or in other words, when I'm single stepping
>with the source debugger, and step through the C++ call
>below...
>
> if (thread2 == NULL) {
> thread2 = new InfoThread2(this); <--- this also runs the thread
> }
> next_function();
>
>Once I step through the allocation and creation of the thread,
>it also runs it.
>
>The debugger would expectedly stop at the "next_function()",
>so when it stops, has the thread executed by this time in its
>entirety? Or is the thread suspended until I continue executing
>the code?
There's no way of knowing. It's a race condition.
When creating threads, you have to assume that you don't know, and can't control, when (or even if) threads start executing once you have created them. It will depend on many factors. While you will usually get consistent behavior on a specific system, the rule for developers is that you never know. You must be prepared for the situations where next_function() gets called before the thread even beings to execute, that the thread has executed completely and exited already, and every possible state in between.
When using the debugger the rules are exactly the same. When you step through the new InfoThread2 statement, you are setting a breakpoint at next_function() and letting your application run. The thread might, or might not, start and it might, or might not, finish before hitting the breakpoint at next_function().
In the debugger, hitting a breakpoint stops all threads. So don't worry about InfoThread2 thread running in the background once you've hit the breakpoint at next_function(). If you want to catch something in your thread, then set a breakpoint in InfoThread2's code as well.
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden