Date: Mon, 11 Aug 2008 21:15:27 +0000
From: Trygve Inda <[EMAIL PROTECTED]>

The real issue here is that I need to use

[self performSelectorOnMainThread:@selector(doUnsafeStuff)
          withObject:nil waitUntilDone:YES];

Which blocks until the method completes, so I need a way to end the thread, but in the original code the killThread method blocks waiting for the thread
to finish.

I tend to agree with Scott's assessment, that you code _appears_ to be going overboard on the locking. It's not clear at all that you need to have any thread blocked waiting for a lock at all.

I also wonder how it is you managed to get yourself into a situation where you've got a worker thread that for some reason is still dependent on code that has to run on the main thread.

That said, without knowing the broader design it's difficult to say for sure. As I and others have pointed out, the code you posted obviously isn't the actual code, so we can't even use that to guide us. Maybe you do in fact have some need for locking that's not apparent to us.

So, if we assume that you do need the locking, then you need to resolve the deadlock somehow of course. And as I mentioned before, it's generally just plain a bad idea to have something in a special thread (like Cocoa's "main thread") wind up blocked on anything at all.

It's not clear at all why you want your main thread to wait for the worker thread to exit, but it seems to me that what you probably ought to be doing is having your worker thread invoke yet another method to be executed on the main thread, just before it exits (and probably with "waitUntilDone:NO" instead).

That would allow you to execute whatever code it is you're trying to execute on the main thread at the time you want it to, but without having the main thread just sit there and wait for the worker thread.

Pete
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to