Threading fixes
During debugging of #419 (closed), I found tons of issues in the multithreading implementation. The most important things which are fixed by this merge request are:
- Trying to queue a signal for a thread, whose environment was write protected by an earlier interrupt attempt would lead to a segmentation fault.
- Interrupt disabling was not always done correctly. Interrupts were not always reenabled again, some parts which needed protection had none, sometimes the wrong mechanism was used (ext::interrupts-enabled instead of env->disable_interrupts needs to be always used when the protected code writes in the thread local environment).
- There was no protection against interrupts for threads which held spinlocks, leading to deadlocks.
- Thread local variables in the environment (env->function, env->values, ...) could be overwritten by interrupting lisp code.
- There was no protection against interrupts during stack manipulations, leading to overwritten stack values or segmentation faults when the interrupting code called frame or binding stack unwind functions.
- The execution of cleanup forms in an unwind-protect could be interrupted, or they could not get executed at all.
- The barrier implementation was not working correctly, the last arriving thread would get stuck in an infinite loop.
I'm sorry that this merge request has become so large, but (nearly) all these changes were necessary to fix #419 (closed). I also found a minor bug in bordeaux-threads (see https://github.com/sionescu/bordeaux-threads/issues/41).
Edited by Marius Gerbershagen