Skip navigation.
 
mlThreads and synchronization (was: Re: Secondary run loops?)
FROM : Cem Karan
DATE : Thu Aug 10 17:27:40 2006

> 1. Start a periodic timer in your main thread and use a shared
> variable to store progress information. You protect your shared
> variables using @synchronized or NSLock objects if necessary (if it's
> just a 32 bit integer storing progress that's not necessary).


Please use locks or @synchronized on everything that's shared, unless 
you are utterly certain that there is no way that corruption of the 
shared data can ever affect you.  I've seen some very, very strange 
problems happen because someone decided that not locking was OK 'just 
this once' which can be easily avoided by locking/synchronizing.

And before you say that it's OK because it is just a 32 bit integer, 
yes, I HAVE seen weirdness that way too; I'll admit, it was on a 
misaligned data access (part of a packed struct), but still, it CAN 
bite you!

Thanks,
Cem Karan

Related mailsAuthorDate
mlThreads and synchronization (was: Re: Secondary run loops?) Cem Karan Aug 10, 17:27
mlRe: Threads and synchronization John Stiles Aug 10, 17:36
mlRe: Threads and synchronization Cem Karan Aug 10, 17:56
mlRe: Threads and synchronization AgentM Aug 10, 19:57
mlRe: Threads and synchronization marc@mac.com Aug 23, 16:59
mlRe: Re: Threads and synchronization Shawn Erickson Aug 23, 17:29
mlRe: Re: Threads and synchronization Michael Ash Aug 23, 17:47
mlRe: Threads and synchronization Chris Suter Aug 24, 02:01