What is the best way to synchronize a data source which is updated frequently from a background thread with the GUI main thread?
Should i put a pthread mutex around each method call?
This seems to be pretty heavy too me.
EDIT: I’m looking for a 10.5 solution
You could always update the model and table view on the main thread. There are functions in NSObject like
performSelectorOnMainThread:withObject:waitUntilDone:that allows you to easily perform a function call on the main thread. So you could update your model with:and then, update your tableview with this:
Things get more complicated if you need to pass more than one object, because then you need to use invocations, but I’ve found that these functions can be used most of the time.