• 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: Techniques for thread communication
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Techniques for thread communication


  • Subject: Re: Techniques for thread communication
  • From: Drew McCormack <email@hidden>
  • Date: Mon, 8 Sep 2003 20:27:03 +0200

I imagine something like this:

@implementation WorkerThread

-(void)whileRunning {
// ...
[controller performSelectorOnMainThread: @(foundMatch)]
// or something equivalent
}

-(Result *)result { return result; }

@implementation MyController

-(void)foundMatch {
[resultToShow release];
resultToShow = [[myWorker result] retain];
[myView setNeedsDisplay: YES];
}

Will this work? Is it a horrible idea?

Seems fine to me. Only thing to be careful about is not to cause problems when you access [myWorker result]. Remember, the performSelectorOnMainThread: is asynchronous, meaning it doesn't wait for foundMatch to finish before continuing. You may need an NSLock in the 'result' method to control access to it.

This is very close to the consumer/producer pattern. You can also solve this with NSConditionLock. It can block one thread until some condition is met, eg. a new result becomes available. Read the docs if you want to know more, and check out cocoadev.com.

http://www.cocoadev.com/index.pl?ProducersAndConsumerModel

Drew

----------------------------------
Dr. Drew McCormack
Trade Strategist (www.trade-strategist.com)
Stock Market strategy design platform for Mac OS X.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Techniques for thread communication (From: Eric Scharff <email@hidden>)

  • Prev by Date: Re: Force NSToolbar to revalidate NOW?
  • Next by Date: Re: Techniques for thread communication
  • Previous by thread: Re: Techniques for thread communication
  • Next by thread: Re: Techniques for thread communication
  • Index(es):
    • Date
    • Thread