3

I've been working on some code recently where I want to ensure that certain tasks run sequentially always execute on the same thread.

As an experiment to get a feel for how this would work I created my own thread using this example Thread Example

My code works fine in that I call a method on the global queue then I enqueue an operation on my Custom Thread.

 func currentQueueName() -> String? {
        let name = __dispatch_queue_get_label(nil)
        return String(cString: name, encoding: .utf8)
    }


DispatchQueue.global().async {
            print(self.currentQueueName())
            myThread.enqueue {
                print(self.currentQueueName())
                //prints "com.apple.root.default-qos.overcommit"
                for i in 1...100 {
                    print(i)
                }
            }
        }

Whenever I print out the current thread during my Custom Thread Execution the thread name says.

("com.apple.root.default-qos.overcommit")

I don't get any errors or crashes.

1) What exactly does this over commit mean?

2) How have I caused it by using my own thread?

3) Is it dangerous to be seeing this message in production code?

4) If it is dangerous how can I use my Custom Thread safely

Update

After reading a post on Swift forum I'm beginning to think that over commit queue refers to any thread that isn't from Dispatch Queue Global.

I'm still not 100% certain though.

dubbeat
  • 7,706
  • 18
  • 70
  • 122
  • Is this answer suitable for you? https://stackoverflow.com/questions/27948618/consistent-dispatch-queue-com-apple-root-default-qos-overcommit-crash – Bohdan Ivanov Aug 27 '19 at 11:36
  • It is very interesting but I dont think so. My test app isn't crashing. I only have 1 dispatch on the global queue and then enqueue to my custom thread. – dubbeat Aug 27 '19 at 11:48
  • 1
    I mean, there is an explanation of over commitment. I've accidentally put link to question instead of answer I'm referring to: https://stackoverflow.com/a/36442699/1840136 This article, https://www.alibabacloud.com/forum/read-494-e, mentions that "The overcommit interface is used to control whether the number of threads can exceed the number of physical cores.", but it is somewhat contradictory to what is being said in mentioned SO answer. – Bohdan Ivanov Aug 27 '19 at 12:19
  • 1
    After reading this I think overcommit is just a 'type' of queue that doenst promise limit the amount of threads on it. Seeing as 'My' queue Thread isnt managed by GCD this jut might be 'normal' . https://forums.swift.org/t/what-is-the-default-target-queue-for-a-serial-queue/18094/11 – dubbeat Aug 27 '19 at 12:44

0 Answers0