Re: Preventing beach balls
Re: Preventing beach balls
- Subject: Re: Preventing beach balls
- From: email@hidden
- Date: Mon, 19 Feb 2007 12:59:53 +1100
...and if you use objects on multiple threads you need to use
techniques to keep them safe (Yay NSRecursive lock), but it's
basically that simple.
#import <canofworms.h>
http://ridiculousfish.com/blog/archives/2007/02/17/barrier/
That article doesn't present anything new in terms of practical
threading, but does make a very lucid observation - multithreading is
conceptually easy, but practically hard because everyone's against
you - everyone being the compiler, the CPU, etc. It's a good read
for those new to threading.
My point is, in particular, that not only are locks not the panacea
for threading, but they have their own problems (deadlock,
serialisation, etc). Locks should really be a last resort - as Mr.
Fish notes, you can accomplish quite a lot of synchronisation just
with a bit of careful design and clever use of memory barriers and
ordering.
Most important of all is your data model. The best model is to not
share data at all - then you've got no thread-safety issues by
definition. Some data structures are naturally suited to this, such
as trees. You can also get around sharing data by passing it back
and forth - i.e. pass it off to your thread when you create it,
forget about it in your main thread, and have your worker thread pass
the results (even if that may be the original data) back to the main
thread using some safe mechanism (e.g.
performSelectorOnMainThread:withObject:, as Seth noted).
There's also Distributed Objects, yes, although for communication
between threads within the same process it's usually overkill.
Wade Tregaskis
ICQ: 40056898
AIM, Yahoo & Skype: wadetregaskis
MSN: email@hidden
iChat & email: email@hidden
http://homepage.mac.com/wadetregaskis/
-- Sed quis custodiet ipsos custodes?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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