Re: Thread deadlock?
Re: Thread deadlock?
- Subject: Re: Thread deadlock?
- From: Trygve Inda <email@hidden>
- Date: Mon, 11 Aug 2008 18:52:16 +0000
- Thread-topic: Thread deadlock?
> Key Trygve,
>
> This looks similar to the threading code we talked about a while
> back. Far be it for me to say that my threading code is bugless :),
> but I haven't run into a deadlock problem, and the code you posted
> has two changes that would give me pause...
>
>
>> [self performSelectorOnMainThread:@selector
>> (doThreadUnsafeStuff)
>> withObject:nil waitUntilDone:YES];
>
> Probably not the problem, but I've often used
> performSelectorOnMainThread: in thread methods, but always passing NO
> to waitUntilDone. What is your doThreadUnsafeStuff doing? In my case,
> it's always just passing a percentage done value back to the main
> thread or something like that. If your thread depends on what
> doThreadUnsafeStuff does, then I guess it has to doe shave wait until
> it's done. But if it's just UI stuff, why wait?
It is doing some stuff that is not Thread Safe and the code following is
dependent up on it.
>> if ([lock lockWhenCondition:kConditionThreadMustExit)
>
> Seems like this may be the real problem. I think Apple misnamed
> lockWhenCondition: - it should've been called "blockUntilCondition".
> With this in mind, isn't the thread loop going to run once, then
> block and stay blocked until the main thread tells it to exit? I
> think it is...
Sorry - this got truncated somehow. Supposed to be:
if ([lock lockWhenCondition:kConditionThreadMustExit beforeDate:[engine
blockUntil]])
This is there because I want the thread to not repeat quickly... Because
this is used to throttle it elsewhere, the block delay will be short
typically.
> Threading code always seems to bring in "just one more thing", and
> doubtless you used the above for good reasons. Looking at it alone,
> though, it just seems like more locking than necessary. The pattern
> I've successfully used (so far - always with the slight suspicion
> that "one more thing" will crop up and break it :) is more like:
I think the issue here is that if I dispatch with
performSelectorOnMainThread (with waitUntilDone:YES), then the thread block
and if killThread gets called while the dispatch is happening but before it
is processed, then each part is waiting for the other.
Not quite sure how to deal with this yet.
Trygve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden