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