Skip to content

Commit e873c0a

Browse files
committed
Added comment that LockFreeMPSCQueue is not linearizable,
removed the corresponding linearizability test.
1 parent 2845fd4 commit e873c0a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeMPSCQueue.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ import java.util.concurrent.atomic.*
2222
private typealias Core<E> = LockFreeMPSCQueueCore<E>
2323

2424
/**
25+
* Lock-free Multiply-Producer Single-Consumer Queue.
26+
* *Note: This queue is NOT linearizable. It provides only quiescent consistency for its operations.*
27+
*
28+
* In particular, the following execution is permitted for this queue, but is not permitted for a linearizable queue:
29+
*
30+
* ```
31+
* Thread 1: addLast(1) = true, removeFirstOrNull() = null
32+
* Thread 2: addLast(2) = 2 // this operation is concurrent with both operations in the first thread
33+
* ```
34+
*
2535
* @suppress **This is unstable API and it is subject to change.**
2636
*/
2737
internal class LockFreeMPSCQueue<E : Any> {
@@ -58,6 +68,10 @@ internal class LockFreeMPSCQueue<E : Any> {
5868
}
5969

6070
/**
71+
* Lock-free Multiply-Producer Single-Consumer Queue core.
72+
* *Note: This queue is NOT linearizable. It provides only quiescent consistency for its operations.*
73+
*
74+
* @see LockFreeMPSCQueue
6175
* @suppress **This is unstable API and it is subject to change.**
6276
*/
6377
internal class LockFreeMPSCQueueCore<E : Any>(private val capacity: Int) {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ class LockFreeMPSCQueueLinearizabilityTest : TestBase() {
3939
@Operation
4040
fun addLast(@Param(name = "value") value: Int) = q.addLast(value)
4141

42-
@Operation(group = "consumer")
43-
fun removeFirstOrNull() = q.removeFirstOrNull()
42+
/**
43+
* Note, that removeFirstOrNull is not linearizable w.r.t. to addLast, so here
44+
* we test only linearizability of close.
45+
*/
46+
// @Operation(group = "consumer")
47+
// fun removeFirstOrNull() = q.removeFirstOrNull()
4448

4549
@Test
4650
fun testLinearizability() {
4751
val options = StressOptions()
48-
.iterations(100)
49-
.invocationsPerIteration(1000 * stressTestMultiplier)
52+
.iterations(100 * stressTestMultiplierSqrt)
53+
.invocationsPerIteration(1000 * stressTestMultiplierSqrt)
5054
.addThread(1, 3)
5155
.addThread(1, 3)
5256
.addThread(1, 3)

0 commit comments

Comments
 (0)