Skip to content

Commit d43fe18

Browse files
authored
Merge pull request swiftlang#39621 from ktoso/wip-harden-task-local-copy-test
[Concurrency] Harden async_task_locals_copy_to_sync
2 parents 85d9507 + 159aad0 commit d43fe18

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
@@ -20,15 +20,13 @@ import Darwin
2020
import Glibc
2121
#endif
2222

23-
@available(SwiftStdlib 5.5, *)
2423
enum TL {
2524
@TaskLocal
2625
static var number: Int = 0
2726
@TaskLocal
2827
static var other: Int = 0
2928
}
3029

31-
@available(SwiftStdlib 5.5, *)
3230
@discardableResult
3331
func printTaskLocal<V>(
3432
_ key: TaskLocal<V>,
@@ -46,9 +44,10 @@ func printTaskLocal<V>(
4644

4745
// ==== ------------------------------------------------------------------------
4846

49-
@available(SwiftStdlib 5.5, *)
5047
func copyTo_sync_noWait() {
5148
print(#function)
49+
let sem = DispatchSemaphore(value: 0)
50+
5251
TL.$number.withValue(1111) {
5352
TL.$number.withValue(2222) {
5453
TL.$other.withValue(9999) {
@@ -58,26 +57,29 @@ func copyTo_sync_noWait() {
5857
TL.$number.withValue(3333) {
5958
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (3333)
6059
printTaskLocal(TL.$other) // CHECK: TaskLocal<Int>(defaultValue: 0) (9999)
60+
sem.signal()
6161
}
6262
}
6363
}
6464
}
6565
}
6666

67-
sleep(1)
67+
sem.wait()
6868
}
6969

70-
@available(SwiftStdlib 5.5, *)
7170
func copyTo_sync_noValues() {
71+
print(#function)
72+
let sem = DispatchSemaphore(value: 0)
73+
7274
Task {
7375
printTaskLocal(TL.$number) // CHECK: TaskLocal<Int>(defaultValue: 0) (0)
76+
sem.signal()
7477
}
7578

76-
sleep(1)
79+
sem.wait()
7780
}
7881

7982
/// Similar to tests in `async_task_locals_copy_to_async_ but without any task involved at the top level.
80-
@available(SwiftStdlib 5.5, *)
8183
@main struct Main {
8284
static func main() {
8385
copyTo_sync_noWait()

0 commit comments

Comments
 (0)