Interrupts and `@spawn` with `ccall`

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 fetching the result:

    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 it looks like all ccalls 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.

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.