aboutsummaryrefslogtreecommitdiff
path: root/atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/test/TraceLFTest.kt
diff options
context:
space:
mode:
Diffstat (limited to 'atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/test/TraceLFTest.kt')
-rw-r--r--atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/test/TraceLFTest.kt76
1 files changed, 0 insertions, 76 deletions
diff --git a/atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/test/TraceLFTest.kt b/atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/test/TraceLFTest.kt
deleted file mode 100644
index 32ea8d8..0000000
--- a/atomicfu/src/jvmTest/kotlin/kotlinx/atomicfu/test/TraceLFTest.kt
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package kotlinx.atomicfu.test
-
-import kotlinx.atomicfu.*
-import kotlin.test.Test
-
-class Counter {
- private val t = Trace(64, TraceFormat { index, text ->
- "$index: [${Thread.currentThread().name}] $text"
- })
- private val a = atomic(0, t)
-
- fun inc(): Int {
- t { "inc() invoked" }
- val x = a.incrementAndGet()
- t { "inc() = $x" }
- return x
- }
-
- internal fun get() = a.value
-}
-
-class CounterDefaultAtomic {
- private val a = atomic(0)
- private val trace = Trace(64)
-
- fun inc(): Int {
- trace { "inc() invoked" }
- val x = a.incrementAndGet()
- trace { "inc() = $x" }
- return x
- }
-
- internal fun get() = a.value
-}
-
-class CounterLFTest : LockFreedomTestEnvironment("CounterLFTest") {
- private val c = Counter()
- private val c1 = CounterDefaultAtomic()
-
- @Test
- fun testCounterDefault() {
- repeat(10) { id ->
- testThread ("Inc-$id") {
- c1.inc()
- }
- }
- repeat(2) { id ->
- testThread("Get-$id") {
- c1.get()
- }
- }
- performTest(10)
- println(c1.get())
- }
-
- @Test
- fun testLockFreedom() {
- repeat(10) { id ->
- testThread("Inc-$id") {
- c.inc()
- }
- }
- repeat(2) { id ->
- testThread("Get-$id") {
- c.get()
- }
- }
- performTest(10)
- println(c.get())
- }
-}
-