I am running into a situation where the read and write operations (being done by two different threads and two different view controllers) to an XML file are overlapping.
I tried the following logic to use the same NSLock with the two view controllers :
ViewControllerOne:
(on a background thread using dispatch_async)
- (void)writeToXML {
// get xmlLock (lock declared globally)
// write
// unlock
}
ViewControllerTwo:
(on the main thread)
- (void)readFromXML {
// get xmlLock (lock referenced from ControllerOne)
// read
// unlock
}
However, while debugging, I am noticing that even when ControllerOne has locked the xmlLock, ControllerTwo is still able to get it.
What am I missing here ? Also, is there a better approach for doing something like this ?