Re: Techniques for thread communication
Re: Techniques for thread communication
- Subject: Re: Techniques for thread communication
- From: Douglas Davidson <email@hidden>
- Date: Mon, 8 Sep 2003 11:30:15 -0700
Yes, of course you can do this. You just need to be sure to lock
around all accesses to the shared data structure, or use some other
strategy to make sure that it is in a consistent state for all threads.
In fact, this is the usual strategy for sharing data across multiple
threads; inter-thread DO is just a means of messaging across threads,
and sending objects that way is a convenience.
Douglas Davidson
On Monday, September 8, 2003, at 10:56 AM, Eric Scharff wrote:
Perhaps I should describe my thread example in more detail. I
have a worker thread that continuously searches an input space
using standard techniques like simulated annealing, genetic
algorithms, etc. The worker thread has a concept of the "best
found so far" which it stores in an instance varable.
The big deal is that the I don't want to pass the search result
around using NSCoding. It can potentially be very large, and it
is wasteful to encode and decode it.
So, my options are
1. Set up an NSTimer on the main thread, that every N seconds
queries the worker thread for the best result so far, and
displays it. Since there is always a "best so far", this method
is always meaningful.
2. A preferred mechanism is to have the worker notify the main
thread when it finds something N percent better than the last
match.
In any of the notificaiton mechanisms, can I avoid sending the
object over the port using NSCoding and simply share the object?
This would seem to work for notificaiton centers, connections,
etc.
_______________________________________________
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.