I'm confused on how to properly use locks with my threads. Here's my setup:
MainController is the main app that updates the UI and spawns some other threads.
MachineObject has some instance variables and methods for updating the data.
MainController updates the UI using data from MachineObject.
Based on an NSTimer, MainController starts a new thread and calls a method in MachineObject to calculate some data which is then put into the instance variables in MachineObject.
MainController also has to update the UI with the information present in the instance variables in MachineObject.
How do I setup the NSLock so that this will all work properly? Do I declare a global lock in MainController.h and allocate it in the init of MainController, then lock it prior to the spawning of the new thread? Can MachineObject then unlock this same lock when it's method (the one started by when the new thread was spawned) is complete?
If I call the updateUI method in MainController within the NSTimer method that also spawns the data collection thread and this thread locks the lock, won't the lock always be locked when the updateUI method wants to use that data to update the UI? Can I use NSConditionalLock to get around this? Should I put the updateUI method on a different timer or can I put it into another thread that sleeps until the lock is unlocked?
thanks,
kman