Re: -[NSThread start] blocks ?!?
Re: -[NSThread start] blocks ?!?
- Subject: Re: -[NSThread start] blocks ?!?
- From: Greg Parker <email@hidden>
- Date: Mon, 28 Sep 2015 13:10:16 -0700
> On Sep 26, 2015, at 3:33 PM, Jerry Krinock <email@hidden> wrote:
>
> 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.
The threads listed are all waiting for a spinlock used by the debugging tools. (Specifically, it's the machinery that records stack traces of queue operations.)
If you see this again, please capture a spindump and file a bug report.
After you file the bug report, you might be able to work around it like this:
defaults write com.apple.dt.Xcode DBGSkipRecordedFrames -bool YES
then quit and relaunch Xcode.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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