Re: Threading - How its done?
Re: Threading - How its done?
- Subject: Re: Threading - How its done?
- From: Michael Vannorsdel <email@hidden>
- Date: Mon, 5 May 2008 23:12:49 -0600
Locks are used as flow gates to keep two threads from interacting with
the same shared data at the same time. For instance if you're adding
objects to an array and at the same time another thread is doing the
same, it will damage the array as neither thread knows someone else is
modifying it at the same time. So you wrap locks around the code
chunks doing the array editing. When one thread is inside the lock
editing the array, other threads will have to wait at the lock until
the holding thread unlocks it, then another thread waiting outside the
lock will be allowed to pass. Since other threads have to wait on
each other, locking hurts the bonuses to using threads but is
sometimes necessary in some places to make sure shared data is not
corrupted. So the goal is to use them sparingly if you're unable to
redesign the code to avoid multiple threads modifying the same piece
of data simultaneously.
Now if two threads are just reading the same piece of data it's ok for
them to do so at the same time, just not ok for one to be modifying
while another might be working with it as well. This is what was
happening with your UI objects, another thread was modifying them
while the main thread was trying to read and draw them.
On May 5, 2008, at 10:46 PM, Karl von Moller wrote:
Many thanks for your reply on this - much appreciated. I did think
it had something to do with the images being swapped out as often
the crashes occurred as I quickly changed selection in the table
view. Because I know nothing about threading, I resorted to anything
to lock the threads. That's why you see my silly attempt at Locking!
Thanks for clearing this up. Cheers Karl
_______________________________________________
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