That happens because DateTime.Now.Ticks
is not very precise and will often return the same value. Have you looked at the data you're creating? Many time
values are equal (depending on how fast your machine is).
The collision can only happen in the middle where the two walking directions meet. The problem should worsen dramatically when you make them walk in the same way.
Use the performance counter to get high-resolution times, use a counter instead, or change the comparison from if (found < TimeLimit.Ticks)
to if (found <= TimeLimit.Ticks)
. The latter will give you results larger than expected from time to time, but never lower than expected.
EDIT
Maybe I'm missing something, but I'm not sure your test can provide reproducible results at all. The check if found < TimeLimit
will always fail once the other thread has finished. However, in the other thread, the check if found < currentTime()
(where currentTime
is a high-performance timer) will practically always result in true, even if the other thread had just updated the document a microsecond before. So the test should yield roughly 1,500 updates, not 1,000. The roughness depends on the precision of the timer and the machine's performance.