<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 22, 2015, at 4:32 PM, Karl Pickett via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Having stack traces on critical faults is an "enterprisey" feature that I like. It would be nice if swift allowed customization of what happened on a trap (like array out of bounds), so it dumped the thread's stack trace to stderr before exiting.<div class=""><br class=""></div><div class="">I can simulate the desired behavior by installing a signal handler for SIGILL, and launch a script that fires up a debugger which attaches to the process and dumps the stack trace(s) before terminating it.</div><div class=""><br class=""></div><div class="">I wrote it in C pretty easily and it is here: <a href="https://gist.github.com/kjpgit/9a1059a5960694767193" class="">https://gist.github.com/kjpgit/9a1059a5960694767193</a><br class=""></div><div class=""><div class=""><br class=""></div><div class="">It's just a small pain to build and link the C code to each swift project. So my question is, can I use pure swift code for the signal handling instead of that C shim.</div><div class=""><br class=""></div><div class="">1) Does swift on linux support an atomic_fetch_add() equivalent out of the box (or some other signal-safe serialization)</div><div class="">2) Any other concerns using swift code in a signal handler. I'd just be using Glibc system calls, and any char data would be pre-allocated.</div></div></div></div></blockquote><br class=""></div><div>You should use the C code. Signal handlers are allowed to do almost nothing. Neither the Swift runtime nor the code generated by the Swift compiler promise to be signal-safe.</div><div><br class=""></div><div><br class=""></div><div>-- </div><div>Greg Parker <a href="mailto:gparker@apple.com" class="">gparker@apple.com</a> Runtime Wrangler</div><div><br class=""></div><br class=""></body></html>