Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Threads and locks, oh my!

Threads and locks, oh my!
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
Apr 12, 2003, 02:13 PM
 
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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:23 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2