In addition to the existing non-thread safe implementation, provide an alternative which would not lose any coverage.
CollectTest (attached) demonstrates that the current implementation is not thread safe. This is the output it provides on my laptop:
FAILED, count = 4998
FAILED, count = 4998
FAILED, count = 4999
FAILED, count = 4999
passed
FAILED, count = 4998
passed
passed
passed
FAILED, count = 4999
passed
FAILED, count = 4999
...
Notice that this example only touches hit() method, rest of the functionality should be made thread safe as well.
CollectTest (attached) demonstrates that the current implementation is not thread safe. This is the output it provides on my laptop:
FAILED, count = 4998
FAILED, count = 4998
FAILED, count = 4999
FAILED, count = 4999
passed
FAILED, count = 4998
passed
passed
passed
FAILED, count = 4999
passed
FAILED, count = 4999
...
Notice that this example only touches hit() method, rest of the functionality should be made thread safe as well.