- I don't want to be updating and reading the file at the same time (because it might be incomplete).
- If the file is not being updated, multiple threads can read the file at the same time.
I've thought about doing this:
object monitor = sharedMonitor;
if (monitor == null)
monitor = new object(); // then we don't lock
lock (monitor) {
read();
}
and so I set the sharedMonitor if I'm updating, but this is risky too (because other code might be reading already).
How can I lock BETWEEN two methods while letting one of the methods multithread happily? I realize that this question is somewhat academic, but the application is going to be used by billions of users someday.
Thanks,
D. Rosenstark
Replies
Know the answer? Post it — somebody with the same question will find it here.