[Top][All Lists]

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

Re: Waiting for threads

From: Richard Frith-Macdonald
Subject: Re: Waiting for threads
Date: Tue, 22 Jul 2003 16:04:32 +0100

On Tuesday, July 22, 2003, at 03:39 PM, Raffael Herzog wrote:



- An object (a) starts a new thread when initialized
- This object a is also a factory for other objects (b), each of which starts its own thread, too - When object a receives a dealloc message, it sets its status accordingly causing all those threads to exit ASAP

The problem is this "ASAP". I don't know exactly *when* a thread actually exited, but I need to make sure that all dependent threads have exited before the object that started them gets deallocated. What I'm looking for is something like Thread#join() in Java:

Thread myThread = new Thread(myRunnable);
// do something...
myThread.requestStop(); // ask the detached thread to exit
myThread.join(); // wait until the thread actually exited

How can this be achieved with GNUstep?

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.

reply via email to

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