{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/16174","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/16174/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/16174/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/16174/events","html_url":"https://github.com/JuliaLang/julia/pull/16174","id":152688567,"number":16174,"title":"Use safepoint to deliver SIGINT","user":{"login":"yuyichao","id":712232,"avatar_url":"https://avatars.githubusercontent.com/u/712232?v=3","gravatar_id":"","url":"https://api.github.com/users/yuyichao","html_url":"https://github.com/yuyichao","followers_url":"https://api.github.com/users/yuyichao/followers","following_url":"https://api.github.com/users/yuyichao/following{/other_user}","gists_url":"https://api.github.com/users/yuyichao/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyichao/subscriptions","organizations_url":"https://api.github.com/users/yuyichao/orgs","repos_url":"https://api.github.com/users/yuyichao/repos","events_url":"https://api.github.com/users/yuyichao/events{/privacy}","received_events_url":"https://api.github.com/users/yuyichao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-05-03T02:36:40Z","updated_at":"2016-05-05T03:36:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JuliaLang/julia/pulls/16174","html_url":"https://github.com/JuliaLang/julia/pull/16174","diff_url":"https://github.com/JuliaLang/julia/pull/16174.diff","patch_url":"https://github.com/JuliaLang/julia/pull/16174.patch"},"body":"This implements @vtjnash 's [idea](https://github.com/JuliaLang/julia/issues/14675#issuecomment-171810732) of delivering sigint in a safer way, without having to add sigatomic to everywhere. This also solves a few performance issues along the way. A brief summary of the differences,\r\n\r\n* Make GC safepoint thread local\r\n\r\n    And create 3 signal pages. See the comment in `safepoint.c` for detail.\r\n    This have a very minor performance hit for accessing safepoint. However, I think we can avoid the safepoint and GC transition around gcframe setup and gcframe pop on x86 so this shouldn't be a big issue. (On ARM, the atomic release store is more expensive than two GC safepoint so we may use a normal store with two safepoint instead, the performance hit of making the safepoint thread local is still very minor in this case though (~5-10% for empty GC frame push/pop, cheaper than the tls getter call....)).\r\n\r\n* Use the GC safepoint mechanism (i.e. SegFault) to deliver InterruptException at known points\r\n\r\n    This automatically makes `ccall` of external library `sigatomic`. (Fix #1468, Fix #2622). In order to avoid waiting too long before the exception is delivered when running unmanaged code, this also implement waking up libuv, abort syscall and abort libsupport io (this use a hack but can be generalized if needed) when sigint arrives. This also implement force throwing of exception if SIGINT arrives too frequently so that one can use `Ctrl-C` to force abort some dead loop. A warning will be printed in such case since it bypass the safe path and even sigatomic.\r\n\r\n    The most important consequence IMHO is that pressing `Ctrl-C` during sysimg compilation should no longer segfault =)\r\n\r\n    This should also make it easier to implement #14675.\r\n\r\n* Make parser and type inference calls sigatomic\r\n\r\n    sigatomic is much cheaper (see below) now so it is now used to protect important runtime code to not be interrupted by `Ctrl-C`.\r\n\r\n* Clean up safepoint and sigatomic, optimize try-catch and `sigatomic`\r\n\r\n    * Split out `safepoint.c`, make `defer_signal` thread local and avoid the expensive atomic ops\r\n    * Make `defer_signal` task local and automatically restore on expection. This eliminate the try-catch needed before in `disable_sigint`.\r\n\r\n        This is technically breaking but `sigatomic_begin` and `sigatomic_end` aren't exported.\r\n\r\n    * Inline `jl_sigatomic_begin` and `jl_sigatomic_end` in codegen.\r\n\r\n    Benchmarking try-catch and `disable_sigint`\r\n\r\n    ```jl\r\n    julia> @inline f1() = try end\r\n    f1 (generic function with 1 method)\r\n\r\n    julia> @inline f2() = disable_sigint(()->nothing)\r\n    f2 (generic function with 1 method)\r\n\r\n    julia> g1(n) = for i in 1:n\r\n               f1()\r\n           end\r\n    g1 (generic function with 1 method)\r\n\r\n    julia> g2(n) = for i in 1:n\r\n               f2()\r\n           end\r\n    g2 (generic function with 1 method)\r\n\r\n    julia> function k(n)\r\n               @time g1(n)\r\n               @time g2(n)\r\n           end\r\n    k (generic function with 1 method)\r\n    ```\r\n\r\n    Timing before\r\n    ```jl\r\n    julia> k(10_000_000)\r\n      0.264041 seconds\r\n      0.401437 seconds\r\n    ```\r\n\r\n    Timing after\r\n    ```jl\r\n    julia> k(10_000_000)\r\n      0.122592 seconds                                                                \r\n      0.012506 seconds\r\n    ```\r\n\r\nClose https://github.com/JuliaLang/julia/pull/12333\r\nClose #12309\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/217070587","html_url":"https://github.com/JuliaLang/julia/pull/16174#issuecomment-217070587","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/16174","id":217070587,"user":{"login":"yuyichao","id":712232,"avatar_url":"https://avatars.githubusercontent.com/u/712232?v=3","gravatar_id":"","url":"https://api.github.com/users/yuyichao","html_url":"https://github.com/yuyichao","followers_url":"https://api.github.com/users/yuyichao/followers","following_url":"https://api.github.com/users/yuyichao/following{/other_user}","gists_url":"https://api.github.com/users/yuyichao/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyichao/subscriptions","organizations_url":"https://api.github.com/users/yuyichao/orgs","repos_url":"https://api.github.com/users/yuyichao/repos","events_url":"https://api.github.com/users/yuyichao/events{/privacy}","received_events_url":"https://api.github.com/users/yuyichao/received_events","type":"User","site_admin":false},"created_at":"2016-05-05T03:36:46Z","updated_at":"2016-05-05T03:36:46Z","body":"Travis linux32 failure is https://github.com/JuliaLang/julia/issues/15920"}}