On Mon, Aug 11, 2008 at 5:15 PM, Trygve Inda <[EMAIL PROTECTED]> wrote: >>> Which part is correct? The original code? >> >> The original code was what I meant. However I was thinking of traditional >> conditions & locks; NSConditionLock does operate at a higher level, and you >> are right that there is no need for an unconditional lock. But really, I >> don't see a need for a lock at all. >> > > 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.
Well, the *real* issue is that you're using two mutually conflicting techniques: 1) Messaging the main thread and blocking until the result is available. 2) Terminating the thread by signaling it and then blocking until it returns the signal. It should be fairly clear, when put in those simple terms, that these guys just aren't going to get along. The good news is that you only need to fix *one* of them. >From what you've shown and said about this code, it sounds like you can probably fix #2 more easily. Just don't block when you signal termination! There may be a reason you need to do this, but if so then I haven't seen it. If you don't need to wait, then don't. Let the secondary thread finish and clean up at leisure. Problem solved. #1 can be fixed without a great deal of effort as well. You'd probably pass NO for waitUntilDone, and then implement your own blocking mechanism using that NSConditionLock. And lastly, you might be able to make #1 go away altogether. In another message you indicated that the main thread messaging is just for writing and downloading files. Unless I misunderstood, there's no reason for either of those to be on the main thread. Mike _______________________________________________ Cocoa-dev mailing list ([email protected]) 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]
