Skip to content

bug: There is no way to get current queue / current queue label under Linux #813

Open
@mman

Description

@mman

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

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