> On Jul 25, 2016, at 12:37 PM, Daniel Stenmark <dstenm...@opentable.com> wrote:
> 
> 2. Can I read from a single file using two NSFileHandles on two threads at 
> the same time?
> 
> Why would you need to do that in the first place?  

To get multithreaded access to the file contents. This is pretty common when 
using databases like SQLite or Realm.

> Unless you’re reading a single byte at a time, it sounds like a sure-fire way 
> to get corrupted data, regardless of whether you’re using NSFileHandle or 
> good old POSIX methods.  I don’t think there’s inherently dangerous about the 
> operation itself, but the resulting data buffers are probably going to be 
> gibberish.

That’s not true. As long as each thread has a separate file handle, they’re 
independent of each other, since each file handle remembers its own offset in 
the file. (Now, if something else is writing to the file at the same time, then 
yes, you can get corrupted data unless you use higher-level synchronization 
like file locking.)

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to