
Simon Marlow
So I think we could adopt a similar policy for STM. The mutex is lockTSO()/unlockTSO(), which is already taken in STM.c:unpark_tso(). To indicate that a thread has already been sent a wakeup message, we could set tso->block_info.closure to a special value - normally it would be END_TSO_QUEUE for a thread blocked in STM. I've been peering at the code a bit, and I'm pretty sure this is safe and doesn't involve many changes to the RTS.
Do you want to try this out and let me know if you get stuck?
Here[1] is a first stab at this. I'm currently waiting for a testsuite run to finish but the patch at very least doesn't seem to break anything obvious. Moreover, the number of wake-ups sent in my benchmark appears to be much more reasonable now. Let me know if there's anything obviously wrong here. Cheers, - Ben [1] https://github.com/bgamari/ghc/commits/stm-mutex