swiftlang / swiftlang/swift-corelibs-libdispatch
bug: There is no way to get current queue / current queue label under Linux
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 2.6k
- Forks
- 496
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
To aid in debugging of multi threaded / multi queue code it is at times useful to obtain a label of the current dispatch queue where a piece of code is executing.
This has been possible using a hacky solution documented by Quinn here:
https://developer.apple.com/forums/thread/701313
And although this works nicely under macOS and iOS, it does not compile under Linux.
import Dispatch
let queue = DispatchQueue(label: "hello-cruel-world")
func main() {
queue.async {
print("DispatchQueue.label: \(queue.label)")
print("dqgl: \(String(cString: __dispatch_queue_get_label(nil)))")
exit(0)
}
dispatchMain()
}
main()
q.swift:8:40: error: cannot find '__dispatch_queue_get_label' in scope
print("dqgl: \(String(cString: __dispatch_queue_get_label(nil)))")
^~~~~~~~~~~~~~~~~~~~~~~~~~
q.swift:8:67: error: 'nil' requires a contextual type
print("dqgl: \(String(cString: __dispatch_queue_get_label(nil)))")
^
Alternatively, or yet better, it may be good to offer an API to get current queue where a piece of code is executing, as from the current queue we can get the label easily.
Please accept my apology if I am missing an obvious way how to achieve this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Linux Dispatch import and the unavailable __dispatch_queue_get_label(nil) entry point, comparing it with the macOS and iOS behavior described in Quinn's linked reference. Determine whether Linux should expose the existing label lookup or provide a current-queue API, then verify that the reported sample compiles and returns the queue label.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, linux, swift
- Domain
- backend-api-design, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100