@@ -19,15 +19,13 @@ import Darwin
19
19
import Glibc
20
20
#endif
21
21
22
- @available ( SwiftStdlib 5 . 5 , * )
23
22
enum TL {
24
23
@TaskLocal
25
24
static var number : Int = 0
26
25
@TaskLocal
27
26
static var other : Int = 0
28
27
}
29
28
30
- @available ( SwiftStdlib 5 . 5 , * )
31
29
@discardableResult
32
30
func printTaskLocal< V> (
33
31
_ key: TaskLocal < V > ,
@@ -45,9 +43,10 @@ func printTaskLocal<V>(
45
43
46
44
// ==== ------------------------------------------------------------------------
47
45
48
- @available ( SwiftStdlib 5 . 5 , * )
49
46
func copyTo_sync_noWait( ) {
50
47
print ( #function)
48
+ let sem = DispatchSemaphore ( value: 0 )
49
+
51
50
TL . $number. withValue ( 1111 ) {
52
51
TL . $number. withValue ( 2222 ) {
53
52
TL . $other. withValue ( 9999 ) {
@@ -57,26 +56,29 @@ func copyTo_sync_noWait() {
57
56
TL . $number. withValue ( 3333 ) {
58
57
printTaskLocal ( TL . $number) // CHECK: TaskLocal<Int>(defaultValue: 0) (3333)
59
58
printTaskLocal ( TL . $other) // CHECK: TaskLocal<Int>(defaultValue: 0) (9999)
59
+ sem. signal ( )
60
60
}
61
61
}
62
62
}
63
63
}
64
64
}
65
65
66
- sleep ( 1 )
66
+ sem . wait ( )
67
67
}
68
68
69
- @available ( SwiftStdlib 5 . 5 , * )
70
69
func copyTo_sync_noValues( ) {
70
+ print ( #function)
71
+ let sem = DispatchSemaphore ( value: 0 )
72
+
71
73
Task {
72
74
printTaskLocal ( TL . $number) // CHECK: TaskLocal<Int>(defaultValue: 0) (0)
75
+ sem. signal ( )
73
76
}
74
77
75
- sleep ( 1 )
78
+ sem . wait ( )
76
79
}
77
80
78
81
/// Similar to tests in `async_task_locals_copy_to_async_ but without any task involved at the top level.
79
- @available ( SwiftStdlib 5 . 5 , * )
80
82
@main struct Main {
81
83
static func main( ) {
82
84
copyTo_sync_noWait ( )
0 commit comments