AngouriMath

Navigation

← Back to list of members

published

 Field

Summary

The same primes as a snapshot nobody mutates, for readers outside the lock.

Remarks

GetPrime used to call EnsurePrimesExist(System.Int32) and then index
primes after the lock had been released, which is not safe for a
List`1 that another thread may be growing: Add reallocates the
backing array, so the reader can see the new Count against the old array and
come back with a different element. A wrong prime is a well-formed integer and
propagates into factorisation rather than throwing. Publishing an array by a single
reference write keeps the read lock-free and correct: a reader takes the reference
once, which is atomic, and then indexes something that is never written again.

























Angouri © 2019-2023 · Project's repo · Site's repo · Octicons · Transparency · 4378 pages online