Verify queue execution versus thread identity

Run a small script that shows why being on a dispatch queue is not the same thing as being off the main thread.

SwiftConcurrencyGCD

Practice

Before discussing @MainActor, interviewers often ask candidates to separate "which queue submitted this work" from "which thread is executing it." Run this read-only snippet and use the output to verify the distinction.

After it runs, answer these out loud:

  1. Why can serialQueue.sync still print true for Thread.isMainThread?
  2. Which part proves that async global work is not on the main thread?
  3. Why is this still not a substitute for @MainActor isolation in app code?
swift 5.2

Run to compile this snippet and inspect its output. Runs Swift 5.2 on the server (Linux); UIKit, SwiftUI, and long-running async are not supported.