Re: Data from thread to NSView, efficiently
Re: Data from thread to NSView, efficiently
- Subject: Re: Data from thread to NSView, efficiently
- From: Chris Hanson <email@hidden>
- Date: Tue, 17 Jul 2007 22:41:10 -0700
On Jul 17, 2007, at 9:45 AM, Jacob Engstrand wrote:
And, of course, if the producer is "too fast" for the consuming main
thread, it should accumulate batches of data and send them of to
newDataAvailable: in chunks. Or, if you _know_ there will be data
and so won't loose performance by polling, let the Producer put the
data in a shared NSArray, and set an NSTimer to let the main thread
harvest the shared NSArray every now and then.
Delivering data _to_ a thread can be done with much less overhead
(very simply using an NSArray to share the data between the
threads), using MPWaitOnSemaphore() and MPSignalSemaphore().
I think you mean NSConditionLock rather than an MPSemaphore above. :)
Producer-consumer by means of a shared work queue is a standard
pattern in multithreaded programming. You should need zero or at most
one invocation of the -[NSObject
performSelectorOnMainThread:withObject:waitUntilDone:] method.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden