[swift-users] Illegal Instruction: 4 OS X libdispatch

Tyler Fleming Cloutier cloutiertyler at aol.com
Tue May 3 12:02:45 CDT 2016


Thanks for the reply, Quinn!

Yep, you’re spot on. The dispatchSource is immediately dealloc’d at the end of the function. The resume I had in there, but I forgot to move it back and uncomment it.

So here’s another interesting question, if I add

 _ = dispatchSource

 to my closure, I can have the closure keep a reference. However, I’ve two concerns with that. One is that looks like something that the compiler might try to optimize out, although in this case perhaps it can’t because of the effect on reference counting. And the second is that I don’t know if the dispatchSource holds a reference to the closure. It seems like it’s possible that it doesn’t, in which case I would avoid a retain cycle.

My motivation for doing something like that is that I would prefer not to make the listen function mutating inside my struct.

> On May 2, 2016, at 1:16 AM, Quinn The Eskimo! via swift-users <swift-users at swift.org> wrote:
> 
> 
> On 1 May 2016, at 19:33, Tyler Fleming Cloutier via swift-users <swift-users at swift.org> wrote:
> 
>> I’m creating a Swift package that uses Dispatch on OS X, but I am getting an Illegal Instruction error after I register my block for an event. Specifically, a UD2 instruction inside of libdispatch:
> 
> Intel code uses the `ud2` illegal instruction for `__builtin_trap`, that is, as a way for the code to stop when some sort of error has been detected.
> 
> In your case I believe that you’re using your dispatch source incorrectly.  Specifically:
> 
> * You should hold on to a reference to `dispatchSource`.
> 
> * You need to `dispatch_resume` the source before it’ll do anything.
> 
> Share and Enjoy
> --
> Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> 
> 
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list