Overview
| Artifact ID: | acb923e5fe6b618ba2d532766a87c9aef9978364 |
|---|---|
| Ticket: | 2869384fffffffffffffffffffffffffffffffff
Tcl_AsyncMark does not work with --enable-threads |
| User & Date: | flatworm on 2009-09-29 15:17:48 |
Changes
- icomment:
I've hit this while implementing an extension to handle POSIX signals (it's unfinished yet so not released). The problem appears to be more complex and I doubt it can be fixed at all for all possible cases of a deadlock, simply because pthread's mutex is allowed to deadlock when locked twice from the same thread, and that's what it does on Linux 2.6 at least. The problem is that the signal handler bumps into the thread's execution stack at unpredictable moments, and hence the signal handling can be considered as a "superthread" which don't play by the usual rules for threads. Conceptually, to make Tcl_AsyncMark() (and any other function which tries to lock the target thread's LTS) not deadlock, we have to make locking function only attempt locking if some flag is not raised (meaning that no lock is held). But using a flag means sharing a mutable state, which inherently implies using another mutex, so we're back at the starting point. Masking all signals before locking the LTS mutex is also a bad idea: a) too many syscalls b) this doesn't help to prevent mutual deadlocks between two threads. So, in my package mentioned above I finally implemented a solution involving a special manager thread with which signal handlers interact and which dispatches events to target threads. The solution is complicated but works. As I intend to release the code under a Tcl-like lisence, I will be happy to share it, if you so wish.
- login: "flatworm"
- mimetype: "text/plain"
- username: "flatworm"