Hi Experts,
I created a simple deadlock program with dispatch concurrent queue but no label:
dispatch_queue_t queueA = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queueA, ^(){
NSLog(@"3:%@", [NSThread currentThread]);
dispatch_barrier_sync(queueA, ^(){
NSLog(@"4:%@", [NSThread currentThread]);
});
});
the output of sample shows the dispatch queue is serial, not concurrent.
2733 Thread_<multiple> DispatchQueue_25: (null) (serial)
2733 start_wqthread (in libsystem_pthread.dylib) + 13 [0x1003bce01]
2733 _pthread_wqthread (in libsystem_pthread.dylib) + 583 [0x1003bd0b7]
2733 _dispatch_worker_thread2 (in libdispatch.dylib) + 125 [0x1003572da]
2733 _dispatch_root_queue_drain (in libdispatch.dylib) + 334 [0x100356824]
2733 _dispatch_async_redirect_invoke (in libdispatch.dylib) + 769 [0x1003463b4]
2733 _dispatch_continuation_pop (in libdispatch.dylib) + 563 [0x1003472be]
2733 _dispatch_client_callout (in libdispatch.dylib) + 8 [0x100343f1b]
2733 _dispatch_call_block_and_release (in libdispatch.dylib) + 12 [0x100342e7c]
2733 __main_block_invoke_2.14 (in learn_oc) + 125 [0x10000176d] main.mm:249
2733 _dispatch_sync_f_slow (in libdispatch.dylib) + 223 [0x10035346c]
2733 __DISPATCH_WAIT_FOR_QUEUE__ (in libdispatch.dylib) + 301 [0x100353c90]
2733 _dispatch_thread_event_wait_slow (in libdispatch.dylib) + 33 [0x1003448ec]
2733 _dispatch_ulock_wait (in libdispatch.dylib) + 47 [0x10034480d]
2733 __ulock_wait (in libsystem_kernel.dylib) + 10 [0x7fff7e3e19de]
But if I create the same concurrent queue with the label, the result is correct:
dispatch_queue_t queueA = dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT);
2891 Thread_34199 DispatchQueue_25: test (concurrent)
+ 2891 start_wqthread (in libsystem_pthread.dylib) + 13 [0x1003bce01]
+ 2891 _pthread_wqthread (in libsystem_pthread.dylib) + 583 [0x1003bd0b7]
+ 2891 _dispatch_worker_thread2 (in libdispatch.dylib) + 125 [0x1003572da]
+ 2891 _dispatch_root_queue_drain (in libdispatch.dylib) + 334 [0x100356824]
+ 2891 _dispatch_async_redirect_invoke (in libdispatch.dylib) + 769 [0x1003463b4]
+ 2891 _dispatch_continuation_pop (in libdispatch.dylib) + 563 [0x1003472be]
+ 2891 _dispatch_client_callout (in libdispatch.dylib) + 8 [0x100343f1b]
+ 2891 _dispatch_call_block_and_release (in libdispatch.dylib) + 12 [0x100342e7c]
+ 2891 __main_block_invoke_2.15 (in learn_oc) + 125 [0x10000176d] main.mm:249
+ 2891 _dispatch_sync_f_slow (in libdispatch.dylib) + 223 [0x10035346c]
+ 2891 __DISPATCH_WAIT_FOR_QUEUE__ (in libdispatch.dylib) + 301 [0x100353c90]
+ 2891 _dispatch_thread_event_wait_slow (in libdispatch.dylib) + 33 [0x1003448ec]
+ 2891 _dispatch_ulock_wait (in libdispatch.dylib) + 47 [0x10034480d]
+ 2891 __ulock_wait (in libsystem_kernel.dylib) + 10 [0x7fff7e3e19de]
It seems like if there is a label in the queue, that means you want to uniquely identify it in debugging tools such as Instruments,
sample
, stackshots, and crash reports, or else the system somehow would change the queue?