The queue is an argument from the caller. I want to know the type (serial or concurrent) of the input dispatch_queue_t because I’ll handle it differently.
Is it possible? and how to check it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If all you have is a
dispatch_queue_tthat was passed to you by “someone else”, there is no way for you to know. That information is effectively hidden from you. If you are creating the queues yourself, then you could usedispatch_queue_set_specificanddispatch_queue_get_specificto stash a value in the queue’s context data, and then read that back out, but if you’re not creating the queue, you’re outta luck.FWIW, this sort of hints at a brittle design/anti-pattern. Taking a queue as a parameter implies that you would schedule blocks for future execution on that queue. From that perspective it shouldn’t matter whether the queue is concurrent or serial.
More to the point, your code should be written such that it doesn’t matter if it’s executed on a serial or concurrent queue. If it uses shared resources, then it should synchronize access to those resources such that if it were to be executed on a concurrent queue, access to those resources would be safe. Conversely, avoid situations in which running on a serial queue would be a problem (i.e. don’t try to achieve recursive locks by using
dispatch_syncwith a queue that might be serial.)