Re: Crash in NSFileManager
Re: Crash in NSFileManager
- Subject: Re: Crash in NSFileManager
- From: j o a r <email@hidden>
- Date: Sat, 8 Nov 2008 22:44:00 -0800
On Nov 8, 2008, at 9:59 PM, David wrote:
I am using NSFileManager on a secondary thread. I am using the
defaultManager.
But during this processing its hard to imagine how the primary thread
could possibly be using the defaultManager.
Isn't the potential issue with NSFileManager that having two threads
use it at the same time can cause problems. If only one thread uses
it, that shouldn't cause a problem should it, even if its the
secondary thread?
If you're using the defaultManager instance you can't necessarily know
if / when someone else is using it. Cocoa itself my access the
defaultManager. You have to alloc+init your own instance if you need
to use NSFileManager from background threads. That's super easy, so
why not?
I can't see why it wouldn't be safe to pass a single, non-shared,
instance of NSFileManager between threads if you can ensure that it's
only ever used by one thread at a time. Not sure why you would need to
do that though.
Stepping back... what I'm trying to do is copy a mess of files which
is time consuming, while allowing the user to cancel. Currently a put
up a window showing a progress indicator and allowing them to cancel.
If they cancel I set the cancel flag for the background thread.
What is the best design approach in Cocoa for this type of scenario?
What you're already doing sounds fine.
Should I avoid using a background thread and do all the processing via
the run loop? I assume I'd then chunk the processing so that I copy
one file at a time in some method invoked off the run loop, while
allowing the UI to continue to run and cancel, setting some flag I
check.
No, you should use a background thread. Trying to perform the work
piecemeal on the main thread will result in a bad user experience.
j o a r
_______________________________________________
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