Binding and multithreading
Binding and multithreading
- Subject: Binding and multithreading
- From: Jonathan Taylor <email@hidden>
- Date: Fri, 23 Mar 2012 11:40:53 +0000
I have been struggling with a problem which I think I have eventually realised is down to me not handling multithreading issues properly. The situation is I have some computationally-demanding code that is running in a separate thread. This has input parameters and state variables associated with it. For diagnostic reasons I would like to be able to display the values of the state variables in the GUI. I had intended to do this just by binding to them. However I am getting occasional "message sent to deallocated instance" errors which I suspect are a symptom of the fact that I am Doing It Wrong. Further reading suggests that because of the way bindings work, modifying those state variables is leading to binding/gui type stuff happening away from the main thread, which appears not to be permitted.
What I can't work out is whether there is a reasonably elegant and uncomplicated way of achieving what I want: the properties in question are being modified from a secondary thread, and I would like to display their values in the GUI, preferably via bindings for convenience. I could for example keep a "shadow object" which the GUI binds to, whose state is updated either periodically or in specific response to changes to properties in the primary object based in the secondary thread. However that strikes me as rather unwieldy and requiring a fair amount of extra code to implement correctly and efficiently. I feel there must be a better way of dealing with my problem - or maybe there isn't, and I just need to accept that bindings etc do not work well in a multithreaded environment. Does anybody have any advice?
Cheers
Jonny
_______________________________________________
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