• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Preventing beach balls
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Preventing beach balls
      • From: Chris Hanson <email@hidden>
References: 
 >Preventing beach balls (From: Paul Borokhov <email@hidden>)
 >Re: Preventing beach balls (From: Seth Willits <email@hidden>)

  • Prev by Date: Re: Preventing beach balls
  • Next by Date: Re: Preventing beach balls
  • Previous by thread: [Moderator] Re: Preventing beach balls
  • Next by thread: Re: Preventing beach balls
  • Index(es):
    • Date
    • Thread