Project

General

Profile

Bug #12252 ยป thread-doc-vm.c.patch

djellemah (John Anderson), 04/06/2016 11:15 AM

View differences:

vm.c
2735 2735
     *
2736 2736
     *	    threads.each { |thr| thr.join }
2737 2737
     *
2738
     *  To retrieve the last value of a thread, use #value
2739
     *
2740
     *      thr = Thread.new { sleep 1; "Useful value" }
2741
     *      thr.value #=> "Useful value"
2742
     *
2738 2743
     *	=== Thread initialization
2739 2744
     *
2740 2745
     *	In order to create new threads, Ruby provides ::new, ::start, and
......
2818 2823
     *
2819 2824
     * 	=== Exception handling
2820 2825
     *
2821
     *	Any thread can raise an exception using the #raise instance method,
2822
     *	which operates similarly to Kernel#raise.
2826
     *  When an unhandled exception is raised inside a thread, it will
2827
     *  terminate. By default, this exception will not propagate to other
2828
     *  threads. The exception is stored and when another thread calls #value
2829
     *  or #join, the exception will be re-raised in that thread.
2830
     *
2831
     *      t = Thread.new{ raise 'something went wrong' }
2832
     *      t.value #=> RuntimeError: something went wrong
2833
     *
2834
     *  An exception can be raised from outside the thread using the
2835
     *  Thread#raise instance method, which takes the same parameters as
2836
     *  Kernel#raise.
2823 2837
     *
2824
     *	However, it's important to note that an exception that occurs in any
2825
     *	thread except the main thread depends on #abort_on_exception. This
2826
     *	option is +false+ by default, meaning that any unhandled exception will
2827
     *	cause the thread to terminate silently when waited on by either #join
2828
     *	or #value. You can change this default by either #abort_on_exception=
2829
     *	+true+ or setting $DEBUG to +true+.
2838
     *  Setting Thread.abort_on_exception = true, Thread#abort_on_exception =
2839
     *  true, or $DEBUG = true will cause a subsequent unhandled exception
2840
     *  raised in a thread to be automatically re-raised in the main thread.
2830 2841
     *
2831 2842
     *	With the addition of the class method ::handle_interrupt, you can now
2832 2843
     *	handle exceptions asynchronously with threads.