Re: Delaying a method return
Re: Delaying a method return
- Subject: Re: Delaying a method return
- From: Kaelin Colclasure <email@hidden>
- Date: Sat, 8 Oct 2005 13:14:28 -0700
On Oct 7, 2005, at 10:36 PM, Steve Weller wrote:
I have a method that returns some data. There is a worker thread
that could be modifying that data, so I call a stopCalculation
method that tells the other thread to stop and exit. However the
worker thread could take a little while to stop since it polls the
variable set by stopCalculation every so often. I know when it has
actually stopped because it calls a didStop delegate method. This
works and is protected against race conditions by a lock.
My question is, after telling the worker thread to stop, how do I
wait for didStop?
I can think of two ways:
1) wait on a semaphore and have the didStop method access the
semaphore
2) implement a -stopCalculation:andWait method that does the
waiting for me (probably by means of a semaphore)
Is there an advantage to doing it via 1) or 2)?
Is there another way that I should be considering?
The notify(3) API is perfect for this sort of thing, assuming you can
live on 10.3 and later.
-- Kaelin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden