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
The following test succeeds if we get the "threadLocal" from the concurrenthashmap (keyed by thread id), but fails if we get it from actually thread local.
classLincheckTest {
val threadLocalCounters =ConcurrentHashMap<Long, AtomicInteger>()
val counter =AtomicInteger(0)
@Test
funmodelCheckingTest(): Unit=ModelCheckingOptions()
.iterations(0) // Change to 300 for exhaustive testing
.addCustomScenario {
parallel {
thread {
actor(::iinc)
actor(::iinc)
}
thread {
actor(::gget)
actor(::gget)
}
thread {
actor(::gget)
actor(::gget)
}
}
}
.invocationsPerIteration(5_000)
.hangingDetectionThreshold(100)
.logLevel(LoggingLevel.INFO)
.check(this::class.java)
@Operation
funiinc(): Int {
val add = getLocalCounter().getAndIncrement()
return counter.addAndGet(add)
}
@Operation
fungget() = counter.get()
// This one works// private fun getLocalCounter() = threadLocalCounters.computeIfAbsent(Thread.currentThread().id) { AtomicInteger(1) }// This one doesntprivatefungetLocalCounter() = localCounter.get()
}
privateval localCounter:ThreadLocal<AtomicInteger> =ThreadLocal.withInitial { AtomicInteger(1) }
The text was updated successfully, but these errors were encountered:
The following test succeeds if we get the "threadLocal" from the concurrenthashmap (keyed by thread id), but fails if we get it from actually thread local.
The text was updated successfully, but these errors were encountered: