• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Delaying a method return
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delaying a method return


  • Subject: Re: Delaying a method return
  • From: Jonathon Mah <email@hidden>
  • Date: Mon, 10 Oct 2005 15:02:55 +0930

Hi Steve,

On 2005-10-08, at 15:06, 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?






Perhaps you could use something like this (typed into Mail):

- (void)doWork
{
// Runs in another thread
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[workingLock lock]; // workingLock is an instance variable of type NSLock
while (!stopCalculation)
// ... do work
[workingLock unlock];
[pool release];
}


- (id)otherMethod
{
    if (![lock tryLock])
        [workerThread stopCalculation];
    [workingLock lock];
    // ...
    [workingLock unlock];
}

So the -[NSLock tryLock] method may be what you're looking for.



Jonathon Mah
email@hidden







_______________________________________________
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


References: 
 >Delaying a method return (From: Steve Weller <email@hidden>)

  • Prev by Date: Objective-C Framework for XML-RPC
  • Next by Date: Re: Help with my stream object please
  • Previous by thread: Re: Delaying a method return
  • Next by thread: Get selected NSManagedObject from a NSPopUpButton
  • Index(es):
    • Date
    • Thread