• 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: Are NSFileWrappers safe for concurrent access?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are NSFileWrappers safe for concurrent access?


  • Subject: Re: Are NSFileWrappers safe for concurrent access?
  • From: Rick Mann <email@hidden>
  • Date: Sat, 25 Jun 2016 14:26:14 -0700

> On Jun 25, 2016, at 12:18 , Quincey Morris <email@hidden> wrote:
>
> On Jun 25, 2016, at 01:40 , Rick Mann <email@hidden> wrote:
>>
>> It seems that they might not be, but I can't find documentation either way.
>
> What do you mean by “access”? Are you referring to their internal state, or their relationship to the file system?
>
> NSFileWrapper is *not* listed as thread-safe:
>
> 	https://developer.apple.com/library/prerelease/content/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html
>
> so I’d assume it comes under the general rubric of “mutable objects”, since the properties that hold file data can change. It’s even possible (though I don’t recall offhand any evidence that makes this a plausible claim) that they access file system information lazily, so even reading properties that don’t change may mutate the internal state.

In my case, I have multi-threaded code that needs to read the contents of individual files in my NSDocument package. No one file is accessed by more than one thread, but they all access the top-level NSFileWrapper to find the files inside. I do not make any changes.

Once I synchronized access to the NSFileWrapper, all was working, so clearly this isn't supported (but I couldn't tell if it should be). Generally it seems non-UI stuff allows for concurrent use, especially reading, but NSFileWrapper seems to be doing a lot of stuff under the hood during traversal of its tree.

Sadly, NSFileWrapper makes it very hard to get independent access to the files. You can't get an NSURL directly from an NSFileWrapper (maybe yo can build one up starting at the top of the document). So I'm currently synchronizing not only the NSFileWrapper access, but also the reads (via regularFileContents). This is not too bad, in my case, since the bulk of the work comes after the read, but still annoying.

Thanks for that thread safety summary. I didn't know that existed.


--
Rick Mann
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


References: 
 >Are NSFileWrappers safe for concurrent access? (From: Rick Mann <email@hidden>)
 >Re: Are NSFileWrappers safe for concurrent access? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Satisfying a protocol - getters vs. functions
  • Next by Date: Re: Security with Streams
  • Previous by thread: Re: Are NSFileWrappers safe for concurrent access?
  • Next by thread: Satisfying a protocol - getters vs. functions
  • Index(es):
    • Date
    • Thread