• 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: passing complex objects between threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: passing complex objects between threads


  • Subject: Re: passing complex objects between threads
  • From: Eric Hermanson <email@hidden>
  • Date: Fri, 24 Apr 2009 21:33:40 -0400

I believe you should use a producer-consumer pattern where the consumer thread waits on a blocking queue for the incoming object, and the producer thread passes the fetched object to the blocking queue after its fetched. There are many examples of producer/consumer on the web...

- Eric


On Apr 24, 2009, at 9:24 PM, Daniel Child wrote:

I have a Core Data app that imports data via a separate managed object contexts. Without multithreading, the operation works fine. But since the import takes over a minute, I want to do the import in a different thread. The data consists of an archived table of data with records.

This is my first time attempting to use threads, and the basic problem I'm having is figuring out the best way to pass the complex object (the table of records) from one thread to another. Since there are something like 50,000 records, deep-copying would be ugly.

I thought of three workarounds.

1. Unarchive the table to be parsed while in the second thread so you have the original, not a copy. Should work, but it's kind of skirting the issue.

2. Create a global variable and copy the table into it . I tried this, but the table's records ivar is still not deep-copied.

3. The thread is called by the app controller with thread's owner set to the app controller itself. i.e. (void) doImportThread: (id) owner [== self / appController]. Theoretically, I should be able to cache the table as appController ivar and access it from within the thread as [owner tableToParse]. I tried this too, and just as with the global variable approach, the actual records are not available within the second thread, only the simple ivars.

This must be a common issue with multithreading. Is there an elegant way to get access to deeper layers of a complex object from within another thread? i.e. a way to make 2) or 3) above work?

Thanks.
_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Re: passing complex objects between threads
      • From: Eric Hermanson <email@hidden>
References: 
 >passing complex objects between threads (From: Daniel Child <email@hidden>)

  • Prev by Date: Re: Core Data and the Application Delegate
  • Next by Date: Re: passing complex objects between threads
  • Previous by thread: passing complex objects between threads
  • Next by thread: Re: passing complex objects between threads
  • Index(es):
    • Date
    • Thread