title: ios write to disk on background thread
body: <p>I am currently writing some files to disk in the background thread just by calling</p>
  
  <pre><code>dispatch_async(my_queue,^{
     [self writeToRoot:filename data:data];
  };
  
  - (BOOL)writeToRoot:(NSString *)path data:(NSData *)content
  {
      NSString *fullPath = [[self rootPath] stringByAppendingPathComponent:path];
  
      NSString *pathWithoutFile = [fullPath stringByDeletingLastPathComponent];
  
      BOOL directoryExists = [[NSFileManager defaultManager] fileExistsAtPath:pathWithoutFile];
  
      if (!directoryExists) {
          NSError *error = nil;
          [[NSFileManager defaultManager] createDirectoryAtPath:pathWithoutFile
                                    withIntermediateDirectories:YES
                                                     attributes:nil error:&amp;error];
          NSParameterAssert(error == nil);
      }
  
      return [content writeToFile:fullPath atomically:NO];
  }
  </code></pre>
  
  <p>I am doing this so as it would not block the main thread. My question is how to ensure thread safety. while this background operation is being carried out, what happens when I try to read from disk the file by calling:</p>
  
  <pre><code>[NSData dataWithContentsOfFile:fullPath];
  </code></pre>
  
  <p>Will be content be corrupted? 
  OR will the write operation lock the file and the read operation will wait until the writing is completed?</p>