dispatch_get_current_queue


Gerriet M. Denkmann
 

macOS 13.6

For debugging purposes I want to test that certain methods do run in the correct queue.

So:
dispatch_queue_t queue = dispatch_get_current_queue();
const char *label = dispatch_queue_get_label(queue);
NSString *qLabel = [NSString stringWithUTF8String: label];

if ( ![ qLabel isEqualToString: supposedLabel ] ) … // error

But Xcode tells me that dispatch_get_current_queue is deprecated.

What to do instead?

Gerriet.


James Walker
 

On Sep 6, 2018, at 3:30 AM, Gerriet M. Denkmann <g@mdenkmann.de> wrote:

macOS 13.6

For debugging purposes I want to test that certain methods do run in the correct queue.

So:
dispatch_queue_t queue = dispatch_get_current_queue();
const char *label = dispatch_queue_get_label(queue);
NSString *qLabel = [NSString stringWithUTF8String: label];

if ( ![ qLabel isEqualToString: supposedLabel ] ) … // error

But Xcode tells me that dispatch_get_current_queue is deprecated.

What to do instead?
Comments in the header dispatch/queue.h suggest using dispatch_assert_queue instead.


Gerriet M. Denkmann
 

On 6 Sep 2018, at 22:24, James Walker <list2@jwwalker.com> wrote:

On Sep 6, 2018, at 3:30 AM, Gerriet M. Denkmann <g@mdenkmann.de> wrote:

macOS 13.6

For debugging purposes I want to test that certain methods do run in the correct queue.

So:
dispatch_queue_t queue = dispatch_get_current_queue();
const char *label = dispatch_queue_get_label(queue);
NSString *qLabel = [NSString stringWithUTF8String: label];

if ( ![ qLabel isEqualToString: supposedLabel ] ) … // error

But Xcode tells me that dispatch_get_current_queue is deprecated.

What to do instead?
Comments in the header dispatch/queue.h suggest using dispatch_assert_queue instead.
Thanks a lot. Exactly what I was looking for.

(Also: The variant dispatch_assert_queue_debug() is compiled out when the preprocessor macro NDEBUG is defined.)

Kind regards,

Gerriet.


bartramf@...
 

Take a look at  `dispatchPrecondition` to test whether code is executing on a specific queue in a pattern like:
 
func foo() {
dispatchPrecondition(condition:  .onQueue(mySpecialQueue))
...
}

Hope it helps.
--
Frederick "Rick" Bartram
bartramf@...
PGP key id: 0x4193BED2  key server: http://pgp.mit.edu


 



On Sep 6, 2018, at 8:51 AM, bartramf@... wrote:

Take a look at  `dispatchPrecondition` to test whether code is executing on a specific queue in a pattern like:

That  may be Swift-only … it doesn't show up in the 10.14 SDK headers. (Gerriet is using Obj-C, as indicated by his code snippet.)

—Jens


bartramf@...
 

Yes, I noticed just after I sent it but it might be helpful to someone else. I apologize to the group for the hasty post.
--
Frederick "Rick" Bartram
bartramf@...
PGP key id: 0x4193BED2  key server: http://pgp.mit.edu