Chapter 3: Infering QoS

“If you submit a task with a higher quality of service than the queue has, the queue’s level will increase. Not only that, but all the operations enqueued will also have their priority raised as well.”

Excerpt From
Concurrency by Tutorials
This material may be protected by copyright.

As stated in the quote, I’m trying to prove programmatically that a queue with lower QoS will be increased if we submit a task with higher QoS. Here’s my code snippet:

let userInitiatedQueue = DispatchQueue.global(qos: .userInitiated)
let utilityQueue = DispatchQueue.global(qos: .utility)

userInitiatedQueue.async {
  print("log from userInitiated queue")

  utilityQueue.async {
    // ❗️debugging at this point, checking `utilityQueue.pos` is still `.utility`
    print("log from utilityQueue queue, it should increase the qos")
  }
}

I assume I am doing it incorrectly. Can you provide a snippet that proves the concept above?

Answer is in Chapter 5: Concurrency Problems, Priority inversion.