Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12838] Cygwin: _swift_once_f has a race condition #55284

Open
belkadan opened this issue May 19, 2020 · 0 comments
Open

[SR-12838] Cygwin: _swift_once_f has a race condition #55284

belkadan opened this issue May 19, 2020 · 0 comments
Labels
Cygwin improvement runtime The Swift Runtime standard library Area: Standard library umbrella

Comments

@belkadan
Copy link
Contributor

Previous ID SR-12838
Radar None
Original Reporter @belkadan
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, Cygwin, Runtime
Assignee None
Priority Medium

md5: 97f5aae70837cdc3a6fe66c2376dd77e

Issue Description:

Cygwin has a custom implementation of swift_once because the compiler only reserves a single word for the "predicate". However, that implementation (in stdlib/public/runtime/CygwinPort.cpp) has a race condition:

  • Thread A calls swift_once

  • Thread B calls swift_once

  • Thread A reads 0 from the predicate

  • Thread A stores 1 into the predicate

  • Thread B reads 1 from the predicate

  • Thread B returns (!!)

  • Thread A executes the initialization

There are really three states here: not-yet-run, running, and already-run.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cygwin improvement runtime The Swift Runtime standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant