• 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: Steve Weller <email@hidden>
  • Date: Sat, 8 Oct 2005 17:02:23 -0700


10.4 or later would be fine.

Is there a more Objective-C/Cocoa way of doing this?

On Oct 8, 2005, at 1:14 PM, Kaelin Colclasure wrote:

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




-- Watch me learn Cocoa http://homepage.mac.com/bagelturf/



_______________________________________________
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>)
 >Re: Delaying a method return (From: Kaelin Colclasure <email@hidden>)

  • Prev by Date: Re: DiskArbitration - not the right framework for getting mounted drive info?
  • Next by Date: Apple Interface Copyright
  • Previous by thread: Re: Delaying a method return
  • Next by thread: Re: Delaying a method return
  • Index(es):
    • Date
    • Thread