Re: Safely terminating a thread, or the dealloc that doesn't
Re: Safely terminating a thread, or the dealloc that doesn't
- Subject: Re: Safely terminating a thread, or the dealloc that doesn't
- From: Glen Low <email@hidden>
- Date: Tue, 16 Mar 2004 08:58:40 +0800
On 16/03/2004, at 2:41 AM, email@hidden wrote:
On Mar 15, 2004, at 9:19 AM, Glen Low wrote:
On 15/03/2004, at 9:27 PM, j o a r wrote:
Maybe I'm being too paranoid. The doco says the receiver for
performSelectorOnMainThread is retained until the perform is complete,
so that should mean the object will still be around until after
perfomSelectorOnMainThread does it job. Still doesn't deal with the
case when the object is dealloc'ed before perform is called...
What makes you suspect that perfomSelectorOnMainThread won't retain the
object until the perform is called? I don't see anything to that end in
the documentation - it just says that the object is retained until the
perform is finished. I read that to mean that it is retained when you
call the method. Wouldn't that make the most sense?
Suppose I have code that does this:
lengthly_operation ();
performSelectorOnMainThread ();
Now during lengthly operation, the main thread might have already
dealloc'ed the object, so that when performSelectorOnMainThread is
called, it is called on a freed object.
Have you actually encountered a problem with the app crashing, or is
this all just hypothetical?
It is hypothetical.
Ah, there's the problem with multithreaded code. It is next to
impossible to recreate the errors, since it really depends on subtle
timing issues -- if you are halfway careful you get code that works 95%
of the time and crashes 5% of the time, often without a good error
report. If I had only one thread to deal with, I'm all for empirical,
unit testing, but with more than 1 thread, I want to sit down, analyze
and cover my bases before running it.
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.