by wireprotocol · 7y ago · 0 comments
First: Never spin waiting on a lock for 3 seconds. If you expect a lock to be released very quickly, you spin K times and then, if you still don't have the lock, try something heavier that can deschedule your process. K should be small enough that your time slice is unlikely to expire while spinning, otherwise, it just causes confusion and wasted work because it looks like your process is doing work when it's not.
Second: It seems dubious that using a feature like system restore causes all Write calls to wait for a lock held by a process in the middle of I/O. I'm sure there are some cases where that must happen (like if out of buffer space to hold the writes), but I would think it would be harder to hit.
EDIT: Rephrased my comment in terms of two problems rather than just the first one.
So it looks more like "process is holding lock A while doing a very long scan through memory". That would fit with the name of the function, too.
The problem was that the system process held the lock for too long, due to some inefficiency in system restore (root cause not yet understood by me).
I agree that it seems dubious, but it is indisputably what was happening, repeatedly.