Uploaded image for project: 'Swift'
  1. Swift
  2. SR-12838

Cygwin: _swift_once_f has a race condition

    XMLWordPrintable

    Details

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            jrose Jordan Rose
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: