Preemptive Multitasking in SDL2

Does SDL have a way for the main thread to destroy a thread that isn’t responding? I looked at the docs but didn’t see anything. My code involves running some statically recompiled code in a sandbox, and I can’t count on it cooperating with the other threads.

Alternatively, is there a good cross-platform threading library for C that works well with SDL and has this functionality?


No, because some platforms don’t offer this, and killing a thread with extreme prejudice is always the wrong thing to do (at a minimum, you get resource leaks, but you could also have it holding a lock that will now never unlock, etc).

If you’re statically recompiling code, can you just stick an “if (some_global_flag_that_means_we_want_to_kill_this_thread) { return; }” in the generated code?

I suppose I could do that, though one of the goals is for the translation to be more human reading. Sticking check_for_quit() at the end of every basic block would clutter things up a bit, especially since some of the programs might have their own threading code that my framework would have to interact with.

Currently I just wanted an easy way to restart the simulation without having to quit and restart the whole program. The plan was to grab all the locks, then kill all the threads and restart them. What does an operating system like OSX do to shut down a process that isn’t responding?

It kills the entire process, not a single thread.

1 Like