You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In random.rng.Utils.longFromSeed, a @volatile counter variable is used. The intent is presumably to guarantee that two RNG constructions initiated during the same nanosecond will result in two independent RNGs. The problem is that the @volatile construct isn't enough to secure a proper concurrent counter variable: it is very possible for two clients to receive the same value from the counter. Thus, the uniquifier isn't doing what it says on the label. This is showcased by the attached ammonite script. (Please run a few times if the result is ∅ at first)
This could be solved using different concurrency primitives, such as synchronized or monix.execution.atomic.
import$ivy.`org.typelevel::spire:0.17.0-M1`importspire.random.rng.Utils.longFromTimeimportconcurrent.{Future, ExecutionContext, Await}
importconcurrent.duration._valnanoTime=0L// fake frozen timer// collect 100 values from the uniquifier successivelydefobserveUniquifier()(implicitec: ExecutionContext):Future[Vector[Long]] =Future { Vector.fill(100) { longFromTime(nanoTime) } }
@main defmain():Unit= {
implicitvalec=ExecutionContext.global
// collect two concurrent sequences from the uniquifierval (l1, l2) =Await.result(observeUniquifier() zip observeUniquifier(), Duration.Inf)
// There should be no overlap, but there usually is
println(l1.toSet & l2.toSet)
}
The text was updated successfully, but these errors were encountered:
In
random.rng.Utils.longFromSeed
, a@volatile
counter variable is used. The intent is presumably to guarantee that two RNG constructions initiated during the same nanosecond will result in two independent RNGs. The problem is that the@volatile
construct isn't enough to secure a proper concurrent counter variable: it is very possible for two clients to receive the same value from the counter. Thus, the uniquifier isn't doing what it says on the label. This is showcased by the attached ammonite script. (Please run a few times if the result is ∅ at first)This could be solved using different concurrency primitives, such as
synchronized
ormonix.execution.atomic
.The text was updated successfully, but these errors were encountered: