-[NSThread start] blocks ?!?
-[NSThread start] blocks ?!?
- Subject: -[NSThread start] blocks ?!?
- From: Jerry Krinock <email@hidden>
- Date: Sat, 26 Sep 2015 15:33:56 -0700
In a OS X app, predating Grand Central Dispatch, in the main thread, I create and start a new thread
NSThread* worker ;
worker = [[NSThread alloc] initWithTarget:instance
selector:@selector(beginWithInfo:)
object:info] ;
[worker setName:@“My Worker thread"] ;
[worker start] ;
usually this works OK, but sometimes, possibly when the above code executes a second or third time in rapid succession, [worker start] will block forever:
Thread 1 Queue : com.apple.main-thread (serial)
#0 0x00007fff93c50cd2 in semaphore_wait_trap ()
#1 0x00000001007614b4 in _dispatch_semaphore_wait_slow ()
#2 0x00007fff9134fae2 in -[NSThread start] ()
Looking at the other threads, I see that “My Worker thread” (see Thread 455, below) has been created, and seems to be stuck while trying to *exit*, which I think is weird because if -[NSThread start] blocked until the new thread exitted, that would defeat the purpose of multithreading. Same thing if, say, My Worker thread executed some kind of “do this on the main thread” call.
Should not -[NSThread start] always return before running any of my code in the new thread? So how could this happen? I’m running OS X 10.11.
Jerry
Here is what some of the other threads are doing. All stacks are completely in Apple’s code.
Thread 453 Queue : com.apple.root.default-qos.overcommit (concurrent)
#0 0x00007fff93c50d92 in syscall_thread_switch ()
#1 0x00007fff9ad85daf in _OSSpinLockLockSlow ()
#2 0x0000000100008135 in gcd_queue_item_enqueue_hook ()
#3 0x000000010077e4d9 in _dispatch_introspection_queue_item_enqueue_hook ()
#4 0x000000010075ba7c in _dispatch_async_f_slow ()
#5 0x00007fff9fe40a1e in LSNotificationReceiver::receiveNotificationFromServer(_xpc_connection_s*, void*) ()
#6 0x00007fff96859986 in _xpc_connection_call_event_handler ()
#7 0x00007fff968581ff in _xpc_connection_mach_event ()
#8 0x000000010075d5be in _dispatch_client_callout4 ()
#9 0x000000010075da65 in _dispatch_mach_msg_invoke ()
#10 0x000000010075966e in _dispatch_queue_drain ()
#11 0x000000010075c00f in _dispatch_mach_invoke ()
#12 0x0000000100757df3 in _dispatch_root_queue_drain ()
#13 0x00000001007578ed in _dispatch_worker_thread3 ()
#14 0x00000001007b6346 in _pthread_wqthread ()
#15 0x00000001007b3f9d in start_wqthread ()
Thread 454 Queue : com.apple.root.utility-qos.overcommit (concurrent)
#0 0x00007fff93c50d92 in syscall_thread_switch ()
#1 0x00007fff9ad85daf in _OSSpinLockLockSlow ()
#2 0x0000000100008d3b in decrement_work_item_refcount ()
#3 0x0000000100008605 in gcd_queue_item_complete_hook ()
#4 0x000000010075847c in _dispatch_root_queue_drain ()
#5 0x00000001007578ed in _dispatch_worker_thread3 ()
#6 0x00000001007b6346 in _pthread_wqthread ()
#7 0x00000001007b3f9d in start_wqthread ()
My worker thread (455)
#0 0x00007fff93c50d92 in syscall_thread_switch ()
#1 0x00007fff9ad85daf in _OSSpinLockLockSlow ()
#2 0x0000000100007af6 in get_entry_from_free_list ()
#3 0x0000000100007a77 in add_thread_info_to_list ()
#4 0x0000000100008143 in gcd_queue_item_enqueue_hook ()
#5 0x000000010077e4d9 in _dispatch_introspection_queue_item_enqueue_hook ()
#6 0x0000000100756cff in _dispatch_barrier_async_f_slow ()
#7 0x00007fff9a00be61 in __CFRunLoopSetOptionsReason ()
#8 0x00007fff9132f4f0 in -[_NSActivityAssertion _end] ()
#9 0x00007fff9132f78c in -[_NSActivityAssertion dealloc] ()
#10 0x00007fff92054b18 in objc_object::sidetable_release(bool) ()
#11 0x00007fff91389ac4 in __delayedPerformCleanup ()
#12 0x00007fff9a033e05 in CFRunLoopTimerInvalidate ()
#13 0x00007fff9a0343f2 in __CFRunLoopTimerDeallocate ()
#14 0x00007fff99faf383 in CFRelease ()
#15 0x00007fff9a0bc983 in ____CFRunLoopDeallocateTimers_block_invoke ()
#16 0x00007fff99ff9bd2 in __CFSetApplyFunction_block_invoke ()
#17 0x00007fff99fe4a20 in CFBasicHashApply ()
#18 0x00007fff99ff9b6a in CFSetApplyFunction ()
#19 0x00007fff9a06eb48 in __CFRunLoopDeallocate ()
#20 0x00007fff99faf383 in CFRelease ()
#21 0x00007fff9a06e4d4 in __CFTSDFinalize ()
#22 0x00000001007b82d9 in _pthread_tsd_cleanup ()
#23 0x00000001007b7e60 in _pthread_exit ()
#24 0x00000001007b8b2d in pthread_exit ()
#25 0x00007fff913befe1 in +[NSThread exit] ()
#26 0x00007fff91350098 in __NSThread__start__ ()
#27 0x00000001007b6815 in _pthread_body ()
#28 0x00000001007b6792 in _pthread_start ()
#29 0x00000001007b3fad in thread_start ()
Thread 456
#0 0x00007fff93c50d92 in syscall_thread_switch ()
#1 0x00007fff9ad85daf in _OSSpinLockLockSlow ()
#2 0x0000000100007af6 in get_entry_from_free_list ()
#3 0x0000000100007a77 in add_thread_info_to_list ()
#4 0x00000001007b680e in _pthread_body ()
#5 0x00000001007b6792 in _pthread_start ()
#6 0x00000001007b3fad in thread_start ()
Thread 457
#0 0x00007fff93c50d92 in syscall_thread_switch ()
#1 0x00007fff9ad85daf in _OSSpinLockLockSlow ()
#2 0x0000000100007af6 in get_entry_from_free_list ()
#3 0x0000000100007a77 in add_thread_info_to_list ()
#4 0x00000001007b6154 in _pthread_wqthread ()
#5 0x00000001007b3f9d in start_wqthread ()
Thread 458
#0 0x00007fff93c50d92 in syscall_thread_switch ()
#1 0x00007fff9ad85daf in _OSSpinLockLockSlow ()
#2 0x0000000100007af6 in get_entry_from_free_list ()
#3 0x0000000100007a77 in add_thread_info_to_list ()
#4 0x00000001007b6154 in _pthread_wqthread ()
#5 0x00000001007b3f9d in start_wqthread ()
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden