Skip navigation.
 
mlRe: Threading - How its done?
FROM : Michael Vannorsdel
DATE : Tue May 06 07:12:49 2008

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

Related mailsAuthorDate
mlRE: Threading - How its done? Karl von Moller May 6, 04:17
mlRe: Threading - How its done? John Calhoun May 6, 04:35
mlRe: Threading - How its done? Michael Vannorsdel May 6, 06:28
mlRe: Threading - How its done? Karl von Moller May 6, 06:46
mlRe: Threading - How its done? Michael Vannorsdel May 6, 07:12
mlRe: Threading - How its done? Karl von Moller May 6, 08:07
mlRe: Threading - How its done? Michael Vannorsdel May 6, 12:19
mlRe: Threading - How its done? Karl von Moller May 6, 13:04
mlRe: Threading - How its done? Michael Vannorsdel May 6, 13:10
mlRe: Threading - How its done? Karl von Moller May 6, 13:19
mlRe: Threading - How its done? Michael Vannorsdel May 6, 14:00
mlRe: Threading - How its done? Karl von Moller May 6, 15:25
mlRe: Threading - How its done? Michael Vannorsdel May 6, 16:52
mlRe: Threading - How its done? Michael Ash May 6, 18:34
mlRe: Threading - How its done? Chris Hanson May 8, 07:26
mlRe: Threading - How its done? Michael Vannorsdel May 8, 08:20
mlRe: Threading - How its done? Chris Hanson May 8, 08:45
mlRe: Threading - How its done? Michael Vannorsdel May 8, 09:16
mlRe: Threading - How its done? Scott Ribe May 8, 17:33
mlRe: Threading - How its done? Michael Vannorsdel May 9, 04:49
mlRe: Threading - How its done? Timothy Reaves May 9, 17:49