• 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: Thread safety with background fetching
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thread safety with background fetching


  • Subject: Re: Thread safety with background fetching
  • From: Jens Alfke <email@hidden>
  • Date: Thu, 31 Jul 2008 16:16:42 -0700


On 31 Jul '08, at 9:59 AM, Ben wrote:

For usage, the summary is that I do:

[NSThread detachNewThreadSelector:@selector(doBackgroundFetch) toTarget:self withObject:nil];

and then -[XMLFetcherParser doYourThing] repeatedly sends newly created objects to receiveItem: using the performSelectorOnMainThread method. Once the spawned thread has done this, it never uses the sent object again.

My question is how should I protect this code from thread related problems? Do I just place @synchronized(){} blocks around the code in receiveItem: and it's counterpart in the spawned thread?

You shouldn't need to. It sounds like -receiveItem: is only called on the main thread, and if the helper object has finished with each new object before it sends it to -receiveItem:, those objects won't be accessed from multiple threads either.


You've basically got an agent-like mechanism, where the threads are very loosely coupled using queues of messages, and don't need to worry about synchronization issues. That's the way I like to arrange things too.

—Jens

_______________________________________________

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


References: 
 >Thread safety with background fetching (From: Ben <email@hidden>)

  • Prev by Date: Re: compiler warning for not fully implementing protocol
  • Next by Date: Re: [Q] [NSValue valueWithBytes: objCType:]
  • Previous by thread: Re: Thread safety with background fetching
  • Next by thread: Re: Thread safety with background fetching
  • Index(es):
    • Date
    • Thread