Re: CoreData & Multithreading...
Re: CoreData & Multithreading...
- Subject: Re: CoreData & Multithreading...
- From: Bill Bumgarner <email@hidden>
- Date: Tue, 24 May 2005 19:08:21 -0700
On May 24, 2005, at 6:45 PM, Lee Morgan wrote:
My CoreData app has a entity (instances of it go upwards of 10,000)
that retrieve information from the internet.
The information is about 50KB for each instance.
I want my app's GUI to run without any interruption when it needs
to retrieve this information - so the natural thought is to create
a thread.
However I still want the entities to remain mutable in the GUI
(they are displayed via a table view) while the worker thread is
updating parts of them. I am willing to "lock" a single entity at a
time (like iTunes does while importing a song).
Since the information is across the network I don't see much of a
reason to make parallel url fetches. Instead I was planing on
either spawning one thread after the previous one ended for each
entity (seems wasteful). Or to create one worker thread with a pool
of entities it needs to update and have it run through them (might
be hard to add / remove entities from this pool?).
Also is there any specific problems related to CoreData and
multithreading? Such as a context can't be used by two threads at
the same time?
I have virtually zero experience with threading. So any
suggestions, advice, cautions, etc. are welcome.
I have a suggestion -- don't use threads. Or, at least, don't
directly use threads. If this is your first real threading
experience, it is going to be very painful. Threads are hard.
The NSURL APIs found in Foundation handle downloading of data in the
background. Assuming that updating of various objects does not take
an inordinately large amount of time, the simplest approach would be
to do the downloads in the background via the NSURL APIs and then
perform the updating in the main event loop.
Keep your update code well isolated...
... because if that proves to not be responsive enough, you can
consider moving the updates to a thread.
b.bum
(And please don't take the above as an insult. I have done a lot of
threaded programming, most of it wrong in hindsight. Even when it
works flawlessly, which is rare, most threaded code has so many
actively toggled mutexes that the app is effectively single
threaded. Threading is just really, really hard.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden