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
@file:Suppress("UNCHECKED_CAST")
packagereproLackingTraceimportjava.util.concurrent.atomic.*importkotlin.math.absoluteValueclassBlaBlaMap<K:Any, V:Any>(initialCapacity:Int) {
privateval table =AtomicReference(Table(initialCapacity))
funput(key:K, value:V): V? {
return table.get().put(key, value)
}
funget(key:K): V? {
return table.get().get(key)
}
funremove(key:K): V? {
return table.get().remove(key)
}
data classFixed(valvalue:Any)
innerclassTable(valcapacity:Int) {
val keys =AtomicReferenceArray<Any?>(capacity)
val values =AtomicReferenceArray<Any?>(capacity)
val nextTable =AtomicReference<Table?>(null)
funput(key:K, value:V): V? {
var index = index(key)
repeat(MAX_PROBES) {
while (true) {
val curKey = keys[index]
when (curKey) {
null-> {
if (!keys.compareAndSet(index, null, key)) continueif (!values.compareAndSet(index, null, value)) continuereturnnull
}
key -> {
while (true) {
val currentValue = values[index]
if (currentValue ==MOVED) {
return resize { tab ->
tab.put(key, value)
} asV?
}
if (currentValue isFixed) {
return resize { tab ->
tab.put(key, value)
} asV?
}
if (!values.compareAndSet(index, currentValue, value)) continuereturn currentValue asV?
}
}
}
index = (index +1) % capacity
break
}
}
resize()
returnthis@BlaBlaMap.put(key, value)
}
funget(key:K): V? {
var index = index(key)
repeat(MAX_PROBES) {
val curKey = keys[index]
when (curKey) {
key -> {
val curValue = values[index]
if (curValue ==MOVED) {
resize()
return table.get()!!.get(key)
}
if (curValue isFixed) {
return curValue.value asV?
}
return values[index] asV?
}
null-> {
returnnull
}
}
index = (index +1) % capacity
}
returnnull
}
funremove(key:K): V? {
var index = index(key)
repeat(MAX_PROBES) {
val curKey = keys[index]
when (curKey) {
key -> {
while (true) {
val curValue = values[index]
if (curValue ==MOVED) {
return resize { tab ->
tab.remove(key)
} asV?
}
if (curValue isFixed) {
return resize { tab ->
tab.remove(key)
} asV?
}
if (!values.compareAndSet(index, curValue, null)) continuereturn curValue asV?
}
}
null-> {
returnnull
}
}
index = (index +1) % capacity
}
returnnull
}
funresize(doAfter: (Table) ->Any? = { null }): Any? {
nextTable.compareAndSet(null, Table(capacity *2))
val next = nextTable.get()!!for (i in0..< capacity) {
while (true) {
val curKey = keys[i]
val curValue = values[i]
// if already moved continueif (curValue ==MOVED) break// if empty or removed -> MOVEDif (curValue ==null) {
if (!values.compareAndSet(i, null, MOVED)) continuebreak
}
// if fixed -> put value and set MOVEDif (curValue isFixed) {
// Set value in new table
next.put(curKey asK, curValue.value asV)
// Set value to moved in this tableif (!values.compareAndSet(i, curValue, MOVED)) continuebreak
}
// if normal value -> fix
values.compareAndSet(i, curValue, Fixed(curValue))
}
}
val resultAfter = doAfter(next)
//Update table referencewhile (true) {
val currentTable = table.get()
if (currentTable.capacity >= nextTable.get()!!.capacity) break
table.compareAndSet(currentTable, nextTable.get())
}
return resultAfter
}
privatefunindex(key:Any) = ((key.hashCode() *MAGIC) % capacity).absoluteValue
}
}
privateconstvalMAGIC=-0x61c88647// golden ratio privateconstvalMAX_PROBES=2privatevalNEEDS_REHASH=Any()
privatevalMOVED=Any()
(edited: put right test with inheritance)
The text was updated successfully, but these errors were encountered:
ndkoval
changed the title
The same test configuration leads to differenct cocurrent scenarios
The same test configuration leads to different concurrent scenarios
Oct 4, 2024
While making a reproducer for a different bug I found out that having inheritance in a test makes lincheck behave differently.
Test without inheritance (this test passes):
Test with inharitance but same settings (this test fails at scenario 20, note all scenarios are different):
DS under test:
(edited: put right test with inheritance)
The text was updated successfully, but these errors were encountered: