# Interrupts and \`@spawn\` with \`ccall\`

**URL:** <https://discourse.julialang.org/t/interrupts-and-spawn-with-ccall/32864>\
**Category:** General Usage\
**Created:** [January 2, 2020, 4:19am UTC](https://discourse.julialang.org/t/interrupts-and-spawn-with-ccall/32864 "2020-01-02T04:19:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [January 2, 2020, 4:19am UTC](https://discourse.julialang.org/t/interrupts-and-spawn-with-ccall/32864/1 "2020-01-02T04:19:01Z")

</div>

I’m calling some C code many times in a loop, and I expect it to spend a lot of its time blocked. To let other Julia tasks take control while my C code is blocked I’m using `@spawn`, then `fetch`ing the result:

```julia
    fetch(Threads.@spawn ccall(...))

```

(This is basically the same as `@threadcall` but I’m under the impression that is deprecated so I’m trying to use the latest-and-greatest. I see similar but not identical strange behavior when using `@threadcall`)

I’m having some issues where `Ctrl-C` seems to be crashing, and I suspect that it might be because the C code is being interrupted in the middle of the `ccall` and left in an inconsistent state. From [#16174](https://github.com/JuliaLang/julia/pull/16174) it looks like all `ccall`s should be sigatomic, but I’m wondering - has anything has changed in that respect with the recent threading support?

Wrapping my `ccall` in a `disable_sigint() do ... end` block seems to solve the problem, which supports that maybe this is the issue.

---

<div class="post-metadata">

**Author:** ![ssfrr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ssfrr/32/3736_2.png) [@ssfrr](https://discourse.julialang.org/u/ssfrr)\
**Post date:** [January 2, 2020, 4:43am UTC](https://discourse.julialang.org/t/interrupts-and-spawn-with-ccall/32864/2 "2020-01-02T04:43:00Z")

</div>

whoops, nevermind - I think the issue was that my Ctrl-C was interrupting the main thread while it was waiting for the `@spawn ccall(...)` result, and then GC was cleaning up some data that the C code depended on, which was causing the segfaults.
