>>> ということは危ないのは RUBY_VM_SET_INTERRUPT() がロストしたときに、タイムアウトなしの
>>> スリープをしていて、vm->running_thread にならないから、タイマースレッドに
>>> 起こして貰えないケースでしょうか?
>>
>>  ちょっとその例が具体的にぱっとわからないのですが,th->interrupt_flag
>> を監視している,前のメールで出してもらった例は危険そうです.危険そう,と
>> 思うのだけど,本当に危険なのかは実は自身が無いのですが.
>
> じゃあパッチつくるから、パッチが汚くなかったらacceptしてくださいよ。危険の
> ありなしをあれこれ悩むよりも建設的です。きっと

しばらく考えたところ、書き込み側で atomic ops 使えば十分という気がしてきました。
それなら、readerは速度低下0なのでパフォーマンス問題がおこりようがないし。
Linuxでしかテストしてませんが、こんなもんでどうでしょうか?
Y29tbWl0IDhlMWZkMDdlYWIwNzAyMTVlYzUyYmRkZTNjZjNkNzdhMWQwMDQxM2UKQXV0aG9yOiBL
T1NBS0kgTW90b2hpcm8gPGtvc2FraS5tb3RvaGlyb0BnbWFpbC5jb20+CkRhdGU6ICAgV2VkIE1h
eSAxMSAyMjoxOTo1MSAyMDExICswOTAwCgogICAgaW50ZXJydXB0IGZsYWcKICAgIAogICAgU2ln
bmVkLW9mZi1ieTogS09TQUtJIE1vdG9oaXJvIDxrb3Nha2kubW90b2hpcm9AZ21haWwuY29tPgot
LS0KIGF0b21pYy5oICB8ICAgMzUgKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysK
IHNpZ25hbC5jICB8ICAgMzYgKysrKysrKysrLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCiB0
aHJlYWQuYyAgfCAgICA5ICsrKysrLS0tLQogdm1fY29yZS5oIHwgICAgOSArKysrKy0tLS0KIDQg
ZmlsZXMgY2hhbmdlZCwgNTQgaW5zZXJ0aW9ucygrKSwgMzUgZGVsZXRpb25zKC0pCgpkaWZmIC0t
Z2l0IGEvYXRvbWljLmggYi9hdG9taWMuaApuZXcgZmlsZSBtb2RlIDEwMDY0NAppbmRleCAwMDAw
MDAwLi44ZGU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