Open
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.
Metadata
Metadata
Assignees
Labels
No labels