D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Thread
/
Filename :
handle_interrupt-c.ri
back
Copy
U:RDoc::AnyMethod[iI"handle_interrupt:ETI"Thread::handle_interrupt;TT:publico:RDoc::Markup::Document:@parts[,o:RDoc::Markup::Paragraph; [I"+Changes asynchronous interrupt timing.;To:RDoc::Markup::BlankLine o; ; [ I"F_interrupt_ means asynchronous event and corresponding procedure ;TI"Cby Thread#raise, Thread#kill, signal trap (not supported yet) ;TI"Fand main thread termination (if main thread terminates, then all ;TI""other thread will be killed).;T@o; ; [I"=The given +hash+ has pairs like <code>ExceptionClass => ;TI"P:TimingSymbol</code>. Where the ExceptionClass is the interrupt handled by ;TI"Kthe given block. The TimingSymbol can be one of the following symbols:;T@o:RDoc::Markup::List: @type: LABEL:@items[o:RDoc::Markup::ListItem:@label[I"+:immediate+;T; [o; ; [I"#Invoke interrupts immediately.;To;;[I"+:on_blocking+;T; [o; ; [I"1Invoke interrupts while _BlockingOperation_.;To;;[I" +:never+;T; [o; ; [I"!Never invoke all interrupts.;T@o; ; [I"Q_BlockingOperation_ means that the operation will block the calling thread, ;TI"Rsuch as read and write. On CRuby implementation, _BlockingOperation_ is any ;TI"$operation executed without GVL.;T@o; ; [I"HMasked asynchronous interrupts are delayed until they are enabled. ;TI".This method is similar to sigprocmask(3).;T@S:RDoc::Markup::Heading: leveli: textI" NOTE;T@o; ; [I"2Asynchronous interrupts are difficult to use.;T@o; ; [I"bIf you need to communicate between threads, please consider to use another way such as Queue.;T@o; ; [I";Or use them with deep understanding about this method.;T@S;;i;I" Usage;T@o; ; [I"@In this example, we can guard from Thread#raise exceptions.;T@o; ; [I"OUsing the +:never+ TimingSymbol the RuntimeError exception will always be ;TI"Bignored in the first block of the main thread. In the second ;TI"Q::handle_interrupt block we can purposefully handle RuntimeError exceptions.;T@o:RDoc::Markup::Verbatim; [I"th = Thread.new do ;TI"9 Thread.handle_interrupt(RuntimeError => :never) { ;TI" begin ;TI"< # You can write resource allocation code safely. ;TI"A Thread.handle_interrupt(RuntimeError => :immediate) { ;TI" # ... ;TI" } ;TI" ensure ;TI"> # You can write resource deallocation code safely. ;TI" end ;TI" } ;TI" end ;TI"Thread.pass ;TI"# ... ;TI"th.raise "stop" ;T:@format0o; ; [I"NWhile we are ignoring the RuntimeError exception, it's safe to write our ;TI"Mresource allocation code. Then, the ensure block is where we can safely ;TI"deallocate your resources.;T@S;;i ;I"Stack control settings;T@o; ; [I"RIt's possible to stack multiple levels of ::handle_interrupt blocks in order ;TI"Hto control more than one ExceptionClass and TimingSymbol at a time.;T@o;; [ I"3Thread.handle_interrupt(FooError => :never) { ;TI"5 Thread.handle_interrupt(BarError => :never) { ;TI"2 # FooError and BarError are prohibited. ;TI" } ;TI"} ;T;0S;;i ;I"$Inheritance with ExceptionClass;T@o; ; [I"SAll exceptions inherited from the ExceptionClass parameter will be considered.;T@o;; [I"4Thread.handle_interrupt(Exception => :never) { ;TI"A # all exceptions inherited from Exception are prohibited. ;TI"} ;T;0o; ; [I"CFor handling all interrupts, use +Object+ and not +Exception+ ;TI"Xas the ExceptionClass, as kill/terminate interrupts are not handled by +Exception+.;T: @fileI" thread.c;T:0@omit_headings_from_table_of_contents_below0I"BThread.handle_interrupt(hash) { ... } -> result of the block ;T0[ I" (p1);T@{FI"Thread;TcRDoc::NormalClass00