Is it Good Idea to Use Swift for Windows / Linux Apps?

This code on Windows

import Foundation
import WinSDK

func onMain() {
  print("is main thread = \(Thread.isMainThread); thread = \(GetCurrentThread())")
}

onMain()

let task = Task {
  onMain()
  precondition(#isolation === MainActor.shared)
  onMain()
  return 5
}

print(await task.value)

prints

is main thread = true; thread = Optional(0xfffffffffffffffe)
is main thread = false; thread = Optional(0xfffffffffffffffe)
is main thread = false; thread = Optional(0xfffffffffffffffe)
5

Code is taken from Equivalence of Task and MainActor.assumeIsolated - #18 by mattie

See also @MainActor behaves different on Windows and macOS

Issue already filed: `DispatchQueue.main` is not bound to main thread on Windows · Issue #846 · swiftlang/swift-corelibs-libdispatch · GitHub

1 Like