[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Waiting for threads

From: Raffael Herzog
Subject: Re: Waiting for threads
Date: Wed, 23 Jul 2003 13:57:49 +0200

Hi Richard,

On 2003-07-22 17:04:32 +0200 Richard Frith-Macdonald <address@hidden> wrote:

You can register as an observer of NSThreadWillExitNotification to see when threads exit (never tried it).

If you need to block until the thread ends, you could have the thread obtain a lock on startup, and release it in the notification observer, then have your main thread block trying to obtain the lock until the exiting thread releases it.

Thanks, that trick with the lock works fine... however, I was rather surprised, that it's possible to release a lock in a thread other than the one that acquired it.

For some reason, I don't receive these NSThreadWillExitNotifications, but I'll investigate that further before I claim having found a bug. :)

But still, some signal class would be a nice thing:

Thread 1:

NSSignal *mySignal = [[NSSignal alloc] init];
[mySignal setDropsSignals: (YES|NO)]; // whether to drop signals or not
// detach new trhead
// do something
[mySignal wait]; // or [signal waitAtMost: aTimeInterval]

Thread 2:

[mySignal send]; // or [signal sendObject: anObject]

cu & thanks,

 The difference between theory and practice is that in theory, there is
                no difference, but in practice, there is.

Raffael Herzog - address@hidden - http://www.raffael.ch - ICQ #67961355

reply via email to

[Prev in Thread] Current Thread [Next in Thread]