xref: /aosp_15_r20/external/kotlinx.atomicfu/integration-testing/examples/jvm-sample/src/main/kotlin/Sample.kt (revision 68017707106cb9da9fed635c150bc497c09c160f)
1 /*
2  * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 import kotlinx.atomicfu.*
6 import kotlin.test.assertEquals
7 import kotlin.test.assertTrue
8 
9 class IntArithmetic {
10     private val _x = atomic(0)
11     val x get() = _x.value
12 
doWorknull13     fun doWork(finalValue: Int) {
14         assertEquals(0, x)
15         assertEquals(0, _x.getAndSet(3))
16         assertEquals(3, x)
17         assertTrue(_x.compareAndSet(3, finalValue))
18     }
19 }
20