PATH:
opt
/
alt
/
ruby34
/
share
/
ri
/
system
U:RDoc::TopLevel[ i I"signals.rdoc:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[S:RDoc::Markup::Heading: leveli: textI"3Caveats for implementing Signal.trap callbacks;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[ I"HAs with implementing signal handlers in C or most other languages, ;TI"Gall code passed to Signal.trap must be reentrant. If you are not ;TI"<familiar with reentrancy, you need to read up on it at ;TI"J{Wikipedia}[https://en.wikipedia.org/wiki/Reentrancy_(computing)] or ;TI"8elsewhere before reading the rest of this document.;T@ o; ;[I"FMost importantly, "thread-safety" does not guarantee reentrancy; ;TI"Dand methods such as Mutex#lock and Mutex#synchronize which are ;TI"=commonly used for thread-safety even prevent reentrancy.;T@ S; ; i;I",An implementation detail of the Ruby VM;T@ o; ;[I"LThe Ruby VM defers Signal.trap callbacks from running until it is safe ;TI"Lfor its internal data structures, but it does not know when it is safe ;TI"Hfor data structures in YOUR code. Ruby implements deferred signal ;TI"9handling by registering short C functions with only ;TI"a{async-signal-safe functions}[http://man7.org/linux/man-pages/man7/signal-safety.7.html] as ;TI"Msignal handlers. These short C functions only do enough tell the VM to ;TI"Lrun callbacks registered via Signal.trap later in the main Ruby Thread.;T@ S; ; i;I"1Unsafe methods to call in Signal.trap blocks;T@ o; ;[I"HWhen in doubt, consider anything not listed as safe below as being ;TI"unsafe.;T@ o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"JMutex#lock, Mutex#synchronize and any code using them are explicitly ;TI"Gunsafe. This includes Monitor in the standard library which uses ;TI"!Mutex to provide reentrancy.;T@ o;;0;[o; ;[I"Dir.chdir with block;T@ o;;0;[o; ;[ I"4any IO write operations when IO#sync is false; ;TI"5including IO#write, IO#write_nonblock, IO#puts. ;TI"EPipes and sockets default to `IO#sync = true', so it is safe to ;TI"/write to them unless IO#sync was disabled.;T@ o;;0;[o; ;[I"JFile#flock, as the underlying flock(2) call is not specified by POSIX;T@ S; ; i;I"7Commonly safe operations inside Signal.trap blocks;T@ o;;;;[ o;;0;[o; ;[I"EAssignment and retrieval of local, instance, and class variables;T@ o;;0;[o; ;[I"AMost object allocations and initializations of common types ;TI"1including Array, Hash, String, Struct, Time.;T@ o;;0;[o; ;[I"PCommon Array, Hash, String, Struct operations which do not execute a block ;TI"Hare generally safe; but beware if iteration is occurring elsewhere.;T@ o;;0;[o; ;[I"BHash#[], Hash#[]= (unless Hash.new was given an unsafe block);T@ o;;0;[o; ;[I"DThread::Queue#push and Thread::SizedQueue#push (since Ruby 2.1);T@ o;;0;[o; ;[I"GCreating a new Thread via Thread.new/Thread.start can used to get ;TI">around the unusability of Mutexes inside a signal handler;T@ o;;0;[o; ;[I"CSignal.trap is safe to use inside blocks passed to Signal.trap;T@ o;;0;[ o; ;[I">arithmetic on Integer and Float (`+', `-', '%', '*', '/');T@ o; ;[ I"EAdditionally, signal handlers do not run between two successive ;TI"Flocal variable accesses, so shortcuts such as `+=' and `-=' will ;TI"Gnot trigger a data race when used on Integer and Float classes in ;TI"signal handlers.;T@ S; ; i;I"BSystem call wrapper methods which are safe inside Signal.trap;T@ o; ;[ I")Since Ruby has wrappers around many ;TI"`{async-signal-safe C functions}[http://man7.org/linux/man-pages/man7/signal-safety.7.html] ;TI"Kthe corresponding wrappers for many IO, File, Dir, and Socket methods ;TI"are safe.;T@ o; ;[I"(Incomplete list);T@ o;;;;[#o;;0;[o; ;[I""Dir.chdir (without block arg);To;;0;[o; ;[I"Dir.mkdir;To;;0;[o; ;[I" Dir.open;To;;0;[o; ;[I"File#truncate;To;;0;[o; ;[I"File.link;To;;0;[o; ;[I"File.open;To;;0;[o; ;[I"File.readlink;To;;0;[o; ;[I"File.rename;To;;0;[o; ;[I"File.stat;To;;0;[o; ;[I"File.symlink;To;;0;[o; ;[I"File.truncate;To;;0;[o; ;[I"File.unlink;To;;0;[o; ;[I"File.utime;To;;0;[o; ;[I" IO#close;To;;0;[o; ;[I"IO#dup;To;;0;[o; ;[I" IO#fsync;To;;0;[o; ;[I"IO#read;To;;0;[o; ;[I"IO#read_nonblock;To;;0;[o; ;[I"IO#stat;To;;0;[o; ;[I"IO#sysread;To;;0;[o; ;[I"IO#syswrite;To;;0;[o; ;[I"IO.select;To;;0;[o; ;[I"IO.pipe;To;;0;[o; ;[I"Process.clock_gettime;To;;0;[o; ;[I"Process.exit!;To;;0;[o; ;[I"Process.fork;To;;0;[o; ;[I"Process.kill;To;;0;[o; ;[I"Process.pid;To;;0;[o; ;[I"Process.ppid;To;;0;[o; ;[I"Process.waitpid;To; ;[I"...;T: @file@:0@omit_headings_from_table_of_contents_below0
[+]
..
[+]
UnicodeNormalize
[+]
OptionParser
[+]
Integer
[+]
Ractor
[+]
Bundler
[-] page-implicit_conversion_rdoc.ri
[edit]
[+]
Digest
[+]
Addrinfo
[-] cache.ri
[edit]
[+]
FloatDomainError
[+]
TCPServer
[+]
KeyError
[+]
SystemCallError
[+]
RactorLocalSingleton
[+]
Prism
[+]
Exception
[+]
SystemStackError
[+]
Hash
[+]
Math
[+]
Rational
[+]
NEWS
[+]
Timeout
[-] page-fiber_md.ri
[edit]
[-] page-extension_rdoc.ri
[edit]
[+]
Shellwords
[-] page-maintainers_md.ri
[edit]
[-] page-marshal_rdoc.ri
[edit]
[+]
English
[+]
Process
[+]
GC
[-] page-extension_ja_rdoc.ri
[edit]
[+]
FiberError
[-] page-dig_methods_rdoc.ri
[edit]
[+]
Singleton
[+]
ARGF
[+]
StringScanner
[+]
Fcntl
[-] page-command_injection_rdoc.ri
[edit]
[+]
File
[+]
ArgumentError
[-] page-LEGAL.ri
[edit]
[+]
Interrupt
[+]
IPAddr
[+]
Benchmark
[+]
Enumerator
[+]
UDPSocket
[+]
Monitor
[-] page-NEWS_md.ri
[edit]
[+]
ENV
[+]
RubyVM
[-] page-index_md.ri
[edit]
[+]
WeakRef
[+]
Reline
[+]
Class
[+]
EncodingError
[-] page-COPYING_ja.ri
[edit]
[+]
TCPSocket
[+]
SOCKSSocket
[-] page-globals_rdoc.ri
[edit]
[+]
Net
[+]
Dir
[+]
Random
[+]
Signal
[-] page-format_specifications_rdoc.ri
[edit]
[-] page-distribution_md.ri
[edit]
[+]
MonitorMixin
[+]
Complex
[+]
SystemExit
[-] page-strftime_formatting_rdoc.ri
[edit]
[-] page-COPYING.ri
[edit]
[+]
Proc
[+]
UNIXSocket
[+]
StringIO
[+]
Refinement
[+]
Readline
[+]
Struct
[+]
RbConfig
[+]
PrettyPrint
[+]
RangeError
[-] page-contributing_md.ri
[edit]
[-] page-ractor_md.ri
[edit]
[+]
PTY
[+]
NameError
[+]
WIN32OLE
[+]
NoMethodError
[+]
Range
[+]
Date
[-] page-bsearch_rdoc.ri
[edit]
[+]
OLEProperty
[+]
NotImplementedError
[+]
FileTest
[+]
Regexp
[+]
Kernel
[+]
BasicObject
[-] page-packed_data_rdoc.ri
[edit]
[+]
Fiddle
[+]
UnboundMethod
[+]
Open3
[+]
optparse
[+]
Marshal
[+]
MatchData
[+]
regexp
[+]
Object
[+]
Coverage
[-] page-encodings_rdoc.ri
[edit]
[+]
ThreadError
[-] page-memory_view_md.ri
[edit]
[-] page-dtrace_probes_rdoc.ri
[edit]
[+]
NoMemoryError
[+]
UNIXServer
[+]
Resolv
[-] page-windows_md.ri
[edit]
[+]
date
[+]
TSort
[+]
EOFError
[+]
Method
[-] page-security_rdoc.ri
[edit]
[+]
URI
[+]
OpenStruct
[+]
FrozenError
[-] page-README_ja_md.ri
[edit]
[+]
IndexError
[+]
ERB
[+]
Comparable
[+]
PStore
[+]
Ripper
[+]
Gem
[+]
SecurityError
[+]
Pathname
[+]
Warning
[+]
Thread
[+]
LoadError
[+]
RegexpError
[+]
Float
[+]
Numeric
[+]
SyntaxSuggest
[+]
RDoc
[+]
Rake
[+]
StandardError
[+]
FalseClass
[-] page-README_md.ri
[edit]
[-] page-character_selectors_rdoc.ri
[edit]
[+]
Encoding
[+]
Time
[+]
YAML
[+]
MakeMakefile
[+]
UncaughtThrowError
[+]
Delegator
[-] page-signals_rdoc.ri
[edit]
[+]
Enumerable
[+]
StopIteration
[+]
ObjectSpace
[+]
ClosedQueueError
[+]
OpenSSL
[-] page-standard_library_md.ri
[edit]
[+]
ErrorHighlight
[+]
IO
[+]
BasicSocket
[+]
BigDecimal
[+]
Win32
[+]
Logger
[+]
PP
[+]
Continuation
[+]
SingleForwardable
[+]
CGI
[+]
JSON
[+]
fatal
[+]
yjit
[+]
Module
[+]
Data
[+]
TypeError
[+]
ThreadGroup
[+]
Zlib
[+]
OpenURI
[+]
SimpleDelegator
[+]
Find
[+]
syntax
[+]
ruby
[+]
SignalException
[+]
FileUtils
[+]
ScriptError
[+]
rjit
[+]
contributing
[+]
ZeroDivisionError
[+]
TrueClass
[+]
NoMatchingPatternKeyError
[+]
DidYouMean
[+]
RuntimeError
[+]
DateTime
[+]
CoreExtensions
[-] page-syntax_rdoc.ri
[edit]
[-] page-exceptions_md.ri
[edit]
[-] page-bug_triaging_rdoc.ri
[edit]
[+]
Etc
[+]
IOError
[+]
Errno
[+]
Fiber
[+]
Symbol
[+]
LocalJumpError
[+]
TracePoint
[+]
NilClass
[+]
Forwardable
[-] page-case_mapping_rdoc.ri
[edit]
[+]
Array
[+]
NoMatchingPatternError
[+]
IPSocket
[+]
SyntaxError
[+]
Binding
[+]
SocketError
[+]
Set
[+]
String
[+]
Socket
[+]
SecureRandom
[+]
Psych
[+]
Tempfile