Skip to content

Commit dd5f6b7

Browse files
committed
[Concurrency] rdar://83940885 Harden async_task_locals_copy_to_sync
1 parent 2b20273 commit dd5f6b7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

test/Concurrency/Runtime/async_task_locals_copy_to_sync.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ import Darwin
1717
import Glibc
1818
#endif
1919

20-
@available(SwiftStdlib 5.5, *)
2120
enum TL {
2221
@TaskLocal
2322
static var number: Int = 0
2423
@TaskLocal
2524
static var other: Int = 0
2625
}
2726

28-
@available(SwiftStdlib 5.5, *)
2927
@discardableResult
3028
func printTaskLocal<V>(
3129
_ key: TaskLocal<V>,
@@ -43,9 +41,10 @@ func printTaskLocal<V>(
4341

4442
// ==== ------------------------------------------------------------------------
4543

46-
@available(SwiftStdlib 5.5, *)
4744
func copyTo_sync_noWait() {
4845
print(#function)
46+
let sem = DispatchSemaphore(value: 0)
47+
4948
TL.$number.withValue(1111) {
5049
TL.$number.withValue(2222) {
5150
TL.$other.withValue(9999) {
@@ -55,26 +54,29 @@ func copyTo_sync_noWait() {
5554
TL.$number.withValue(3333) {
5655
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (3333)
5756
printTaskLocal(TL.$other) // CHECK: TaskLocal<Int>(defaultValue: 0) (9999)
57+
sem.signal()
5858
}
5959
}
6060
}
6161
}
6262
}
6363

64-
sleep(1)
64+
sem.wait()
6565
}
6666

67-
@available(SwiftStdlib 5.5, *)
6867
func copyTo_sync_noValues() {
68+
print(#function)
69+
let sem = DispatchSemaphore(value: 0)
70+
6971
Task {
7072
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (0)
73+
sem.signal()
7174
}
7275

73-
sleep(1)
76+
sem.wait()
7477
}
7578

7679
/// Similar to tests in `async_task_locals_copy_to_async_ but without any task involved at the top level.
77-
@available(SwiftStdlib 5.5, *)
7880
@main struct Main {
7981
static func main() {
8082
copyTo_sync_noWait()

0 commit comments

Comments
 (0)