File tree 1 file changed +14
-9
lines changed
atomicfu/src/concurrentTest/kotlin/kotlinx/atomicfu/locks
1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -16,39 +16,44 @@ class ThreadParkerTest {
16
16
ParkingSupport .park(Duration .INFINITE )
17
17
}
18
18
19
- // Allow thread to be parked before park call
19
+ // Allow thread to be parked before unpark call
20
20
sleepMillis(100 )
21
21
ParkingSupport .unpark(parkingHandle!! )
22
22
23
23
f.waitThrowing()
24
24
}
25
-
26
25
27
26
@Test
28
27
fun unparkPark () {
29
- var parkingHandle : ParkingHandle ? = null
28
+ val atomicHandle = AtomicParkingHandle ()
30
29
val unparked = AtomicBoolHolder (false )
31
30
32
31
val f = Fut {
33
- parkingHandle = ParkingSupport .currentThreadHandle()
32
+ atomicHandle.atomicHandle.value = ParkingSupport .currentThreadHandle()
34
33
35
34
while (! unparked.atomicBool.value) {
36
35
sleepMillis(10 )
37
36
}
38
37
39
38
ParkingSupport .park(Duration .INFINITE )
40
39
}
41
-
42
- // allow testThread to start and publish handle
43
- sleepMillis(100 )
44
40
45
- ParkingSupport .unpark(parkingHandle!! )
41
+ while (atomicHandle.atomicHandle.value == null ) {
42
+ sleepMillis(10 )
43
+ }
44
+
45
+ ParkingSupport .unpark(atomicHandle.atomicHandle.value!! )
46
46
unparked.atomicBool.value = true
47
47
48
48
f.waitThrowing()
49
49
50
50
}
51
-
51
+
52
+ // Needs to be in class otherwise build complains having an atomic outside of constructor
53
+ private class AtomicParkingHandle () {
54
+ val atomicHandle = atomic<ParkingHandle ?>(null )
55
+ }
56
+
52
57
// Needs to be in class otherwise build complains having an atomic outside of constructor
53
58
private class AtomicBoolHolder (initial : Boolean ) {
54
59
val atomicBool = atomic(initial)
You can’t perform that action at this time.
0 commit comments