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