From: nobu@... Date: 2017-12-23T07:43:08+00:00 Subject: [ruby-core:84415] [Ruby trunk Misc#14222] Mutex.lock is not safe inside signal handler: what is? Issue #14222 has been updated by nobu (Nobuyoshi Nakada). `Thread.handle_interrupt` doesn't work. You can use `Queue` inside trap context. ```ruby require 'logger' LOG = Queue.new Thread.start { log = Logger.new(STDOUT) log.info "Now logging!" nil while log.info(LOG.pop) } trap :INT do LOG << "Hello" end gets ``` ---------------------------------------- Misc #14222: Mutex.lock is not safe inside signal handler: what is? https://bugs.ruby-lang.org/issues/14222#change-68606 * Author: hkmaly (Honza Maly) * Status: Open * Priority: Normal * Assignee: ruby-core ---------------------------------------- As mentioned in #7917, Mutex.lock is not safe inside signal handler. As mentioned in #6416, neither is Thread.join. But there seem to be no documentation about what IS safe to do inside signal handler. In C, it is not safe to just modify variable inside signal handler without locking. Is it safe in ruby in case of 1) global variable 2) class variable 3) object variable 4) thread local variable, as in Thread.current['local_var'] ? Is there any other method of locking usable inside trap content? Note that while response in this issue would be useful it would be even better if it appeared in official ruby documentation, if there is any. I realize it is not directly bug but it's likely going to be cause of many bugs if the answer is "no" on any part of this and only people who understand ruby core can answer this. -- https://bugs.ruby-lang.org/ Unsubscribe: