passing complex objects between threads
passing complex objects between threads
- Subject: passing complex objects between threads
- From: Daniel Child <email@hidden>
- Date: Fri, 24 Apr 2009 21:24:23 -0400
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