Skip to content

Commit 4ecd46b

Browse files
committed
Use randomSpinWaitIntermission in multi-step operations
1 parent 2324fd0 commit 4ecd46b

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/internal/LockFreeLinkedListAtomicStressLFTest.kt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,22 @@ class LockFreeLinkedListAtomicStressLFTest : TestBase() {
5656
val list = lists[rnd.nextInt(nLists)]
5757
val node = IntNode(threadId)
5858
list.addLast(node)
59-
burnTime(rnd)
59+
randomSpinWaitIntermission()
6060
tryRemove(node)
6161
}
6262
1 -> {
6363
// just to test conditional add
6464
val list = lists[rnd.nextInt(nLists)]
6565
val node = IntNode(threadId)
6666
assertTrue(list.addLastIf(node, { true }))
67-
burnTime(rnd)
67+
randomSpinWaitIntermission()
6868
tryRemove(node)
6969
}
7070
2 -> {
7171
// just to test failed conditional add and burn some time
7272
val list = lists[rnd.nextInt(nLists)]
7373
val node = IntNode(threadId)
7474
assertFalse(list.addLastIf(node, { false }))
75-
burnTime(rnd)
7675
}
7776
3 -> {
7877
// add two atomically
@@ -95,8 +94,9 @@ class LockFreeLinkedListAtomicStressLFTest : TestBase() {
9594
}
9695
}
9796
assertTrue(op.perform(null) == null)
98-
burnTime(rnd)
97+
randomSpinWaitIntermission()
9998
tryRemove(node1)
99+
randomSpinWaitIntermission()
100100
tryRemove(node2)
101101
}
102102
else -> error("Cannot happen")
@@ -141,17 +141,6 @@ class LockFreeLinkedListAtomicStressLFTest : TestBase() {
141141
lists.forEach { it.validate() }
142142
}
143143

144-
private val sink = IntArray(1024)
145-
146-
private fun burnTime(rnd: Random) {
147-
if (rnd.nextInt(100) < 95) return // be quick, no wait 95% of time
148-
do {
149-
val x = rnd.nextInt(100)
150-
val i = rnd.nextInt(sink.size)
151-
repeat(x) { sink[i] += it }
152-
} while (x >= 90)
153-
}
154-
155144
private fun tryRemove(node: IntNode) {
156145
if (node.remove())
157146
undone.incrementAndGet()

0 commit comments

Comments
 (0)