data written to a file is not propagated immediately

Hi,
In my code i try to overwrite data on image save


NSData * mediaData = UIImageJPEGRepresentation(image)
[mediaData writeToFile:file options:NSDataWritingAtomic error:&err];


Once this operation is completed , i try to read the data from the same file but on different thread
I somehow get back the old data , rather than the new written data.


I am reading

[NSData dataWithContentsOfFile:localImageUrl options:NSDataReadingUncached error:&err]


-Pavan

Answered by DTS Engineer in 41028022

I suspect you have a race condition here, that is, your reader thread is reading the data before your writer thread has finished. The NSData calls you reference do not buffer the data in user space, and the kernel’s file system cache is coherent.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Accepted Answer

I suspect you have a race condition here, that is, your reader thread is reading the data before your writer thread has finished. The NSData calls you reference do not buffer the data in user space, and the kernel’s file system cache is coherent.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Yeah , u are rite that was the issue, i figured it out ... Thanks

data written to a file is not propagated immediately
 
 
Q