Skip to content

DispatchQueue.main is not bound to main thread on Windows #846

Open
@HeMet

Description

@HeMet
@main
struct EntryPoint3: AsyncParsableCommand {
    @MainActor
    mutating func run() async throws {
        print("Thread is main: \(Thread.isMainThread)")
        print("Current Thread ID: \(GetCurrentThreadId())")
        MainActor.preconditionIsolated()
        await withCheckedContinuation { con in
            DispatchQueue.main.async {
                print("Thread is main (queue): \(Thread.isMainThread)")
                print("Current Thread ID (queue): \(GetCurrentThreadId())")
                MainActor.preconditionIsolated()
                con.resume()
            }
        }
        print("completed")
    }
}

Output:

Thread is main: false
Current Thread ID: 498188
Thread is main (queue): false
Current Thread ID (queue): 498188
completed

Thread on Swift Forums https://forums.swift.org/t/mainactor-behaves-different-on-windows-and-macos/74742

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions