swiftlang / swiftlang/swift-corelibs-libdispatch

`DispatchQueue.main` is not bound to main thread on Windows

Open
#846 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Linux Windows
Dominant language
C
Stars
2.6k
Forks
496
Avg merge
2d 6h
Merged PRs (30d)
3

Description

@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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided EntryPoint3 reproducer on Windows and compare the reported thread IDs and MainActor checks with the expected main-thread behavior. Trace the Windows handling of DispatchQueue.main; done means the queued closure executes on the main thread while the existing continuation completes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, swift
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.