How to pause a pthread ANY TIME I want?

The Modula-3 garbage collector needs to suspend pthreads at an arbitrary time, not just when they are waiting on a condition variable or mutex. It does it by registering a (Unix) signal handler that suspends the thread and then using pthread_kill to send a signal to the target thread. I think it works (it has been reliable for others but I’m debugging an issue with it right now…) It’s a bit kludgy, though….

Google for ThreadPThread.m3 and look at the routines “StopWorld” and “StartWorld”. Handler itself is in ThreadPThreadC.c.

Leave a Comment