Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about dispatch_sync #5

Closed
leonerd42 opened this issue Apr 14, 2015 · 3 comments
Closed

A question about dispatch_sync #5

leonerd42 opened this issue Apr 14, 2015 · 3 comments

Comments

@leonerd42
Copy link
Contributor

In the initializer of ImageCache:

dispatch_sync(ioQueue, { () -> Void in
    self.fileManager = NSFileManager()
})

Why not use self.fileManager = NSFileManager() directly?

@onevcat
Copy link
Owner

onevcat commented Apr 14, 2015

While NSFileManager.defaultManager() is thread-safe, the file manager created by NSFileManager() is not. So there is a possibility of creating the file manager in a thread, but using it in another. An ioQueue could ensure all file IOs are in the same thread.

See the "Threading Considerations" section in NSFileManager doc.

@onevcat onevcat closed this as completed Apr 14, 2015
@leonerd42
Copy link
Contributor Author

Do you mean that self.fileManager may be used when initializing an instance of ImageCache?

@onevcat
Copy link
Owner

onevcat commented Apr 14, 2015

Hi, in fact here should be no problem to just use fileManager = NSFileManager(), or even use a defaultManager. But if you want to add some delegate later, you will need a new created file manager and consider the thread problem.

Here I prefer a new file manager since Kingfisher is a framework and should be isolated in the io operations from the "host" app, which might be using the shared file manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants