summaryrefslogtreecommitdiff
path: root/thread.c
AgeCommit message (Collapse)Author
2012-11-28* thread.c (rb_mutex_sleep): fix to allow spurious wakeup.ko1
* NEWS: write about spurious wakeup. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37943 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28* include/ruby/thread.h (rb_thread_call_without_gvl2): changeko1
meaning of function. This function is called with same parameters of `rb_thread_call_without_gvl()'. However, if interrupts are detected, when return immediately. * thread.c: implement `rb_thread_call_without_gvl2()'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37938 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28 * thread.c (thread_join_sleep): check spurious wakeup by itself fortarui
corresponding status change in trap context. * vm_core.h (struct rb_thread_struct): add rb_thread_list_t and use as join_list for reentry by trap context. * thread.c (thread_start_func_2): ditto. * thread.c (remove_from_join_list): ditto. * thread.c (rb_thread_atfork): ditto. * thread.c (thread_join): ditto. & remove trap handler check. * thread.c (sleep_forever): add argument : spurious_check. * thread.c (sleep_timeval): ditto. * thread.c (rb_thread_sleep_forever): set spurious_check. * thread.c (rb_thread_sleep_deadly): ditto. * thread.c (sleep_for_polling): ditto. * thread.c (rb_thread_wait_for): ditto. * thread.c (sleep_wait_for_interrupt): bypass spurious_check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37937 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28* vm_core.h (enum rb_thread_status): remove THREAD_TO_KILLkosaki
* vm_core.h (struct rb_thread_struct): add to_kill field * thread.c (terminate_i): convert THREAD_TO_KILL to to_kill. * thread.c (rb_threadptr_to_kill): ditto. * thread.c (rb_thread_kill): ditto. * thread.c (rb_thread_wakeup_alive): ditto. * thread.c (thread_list_i): ditto. * thread.c (static const char): ditto. * thread.c (thread_status_name): ditto. * thread.c (rb_thread_status): ditto. * thread.c (rb_thread_inspect): ditto. * vm_backtrace.c (thread_backtrace_to_ary): ditto. * thread.c (rb_threadptr_execute_interrupts): fix thread status overwritten issue. [Bug #7450] [ruby-core:50249] * test/ruby/test_thread.rb (test_hread_status_raise_after_kill): test for the above. * test/ruby/test_thread.rb (test_thread_status_in_trap): test for thread status in trap. * test/ruby/test_thread.rb (test_status_and_stop_p): remove Thread.control_interrupt unsafe test. Thread#kill no longer changes thread status. Instead of, Thread#kill receiver changes their own status when receiving kill signal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28* thread.c (struct rb_mutex_struct): add allow_trap field.kosaki
* internal.h (rb_mutex_allow_trap): added. * thread.c (rb_mutex_lock, rb_mutex_unlock): check mutex->allow_trap. * thread.c (mutex_sleep): remove trap check because it uses rb_mutex_lock and rb_mutex_unlock internally. * thread.c (rb_mutex_allow_trap): new helper function for the above. * io.c (io_binwrite): mark fptr->write_lock as writable in trap. * test/ruby/test_signal.rb (test_trap_puts): test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37930 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28* thread.c (rb_mutex_lock): moved trap context check fromkosaki
rb_mutex_trylock because try_lock have no change to make a deadlock. * thread.c (rb_mutex_trylock): ditto. * NEWS: news for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28* thread.c (thread_s_new): uses main_thread->status instead ofkosaki
th->inhibit_thread_creation for preventing thread creation. * vm_core.h (rb_vm_struct): remove inhibit_thread_creation field. * thread.c (rb_thread_terminate_all): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37921 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-28* thread.c (thread_join): A trap handler check was moved fromkosaki
thread_join_m because Thread#value should be raised an exception too. * thread.c (thread_join_m): remove trap handler check. * test/ruby/test_thread.rb (test_thread_join_in_trap): add test for thread#value. * NEWS: documentation fix for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27* thread.c (rb_thread_terminate_all): retry broadcast only whenko1
an exception is raised. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27* thread.c (rb_thread_terminate_all): broadcast terminate eventko1
not only an interrupt exception but any exceptions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27* thread.c (rb_thread_terminate_all): suppress a warning.kosaki
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27* thread.c (thread_join): raises ThreadError if target theradkosaki
is a main thread. * test/ruby/test_thread.rb (test_thread_join_main_thread): test for the above. * NEWS: news for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-27* thread.c (thread_join): raises ThreadError if target threadkosaki
is a current thread. * test/ruby/test_thread.rb (test_thread_join_current): test for the above. * NEWS: news for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* thread.c (rb_thread_terminate_all): broadcast eTerminateSignalkosaki
again when Ctrl-C was pressed. [Feature #1952] [ruby-dev:39107] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37875 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* thread.c (rb_thread_terminate_all): add RUBY_VM_CHECK_INTS_BLOCKING().kosaki
Otherwise the loop in this function behave as busy loop because native_sleep() return immediately when RUBY_VM_INTERRUPTED() is true. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* thread.c (rb_mutex_trylock, rb_mutex_unlock, mutex_sleep):kosaki
raises ThreadError if called from trap handler as Thread#join. * NEWS: news fot the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* thread.c (rb_thread_terminate_all): use native_sleep() insteadkosaki
of rb_thread_schedule(). Otherwise, it consume 100% cpu meaninglessly. [Bug #5368] [ruby-dev:44546] * thread.c (thread_start_func_2): last sub-thread wakes up main thread. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* vm_core.h (RUBY_VM_SET_TIMER_INTERRUPT, RUBY_VM_SET_INTERRUPT)kosaki
(RUBY_VM_SET_FINALIZER_INTERRUPT, RUBY_VM_SET_TRAP_INTERRUPT) (RUBY_VM_INTERRUPTED): use enum symbol instead of immediate value. * thread.c (thread_join_m, rb_threadptr_execute_interrupts): ditto. * signal.c (signal_exec): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37864 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* thread.c (thread_join_m): use th->interrupt_mask instead ofkosaki
th->in_trap. * vm_core.h (struct rb_thread_struct): remove in_trap member. * signal.c (signal_exec): ditto. * thread.c (thread_create_core): ditto. * thread.c (Init_Thread): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* ruby_atomic.h (ATOMIC_CAS): new macro for compare-and-exchange.kosaki
* vm_core.h (struct rb_thread_struct): add interrupt_mask member. * thread.c (thread_create_core, Init_Thread): initialize th->thread_mask. * vm_core.h (RUBY_VM_INTERRUPTED_ANY): new macro for avoiding bare th->interrupt_flag. * vm_core.h (RUBY_VM_INTERRUPTED, RUBY_VM_INTERRUPTED): check th->interrupt_mask. * thread.c (set_unblock_function, rb_thread_schedule): replace th->interrupt_flag with RUBY_VM_INTERRUPTED_ANY() * signal.c (signal_exec): set up thread->interrupt_mask for preventing recursive trap handler. * vm_core.h (RUBY_VM_CHECK_INTS, RUBY_VM_CHECK_INTS_BLOCKING): ditto. * thread.c (rb_threadptr_execute_interrupts): don't process interrupt if it is masked. [Bug #6009] [ruby-core:42524] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26split trap interrupt and async interruptkosaki
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-26* vm_core.h (rb_thread_struct): added 'in_trap' member for markingkosaki
running trap handler. * signal.c (signal_exec): turn on in_trap when running trap. * thread.c (Init_Thread, thread_create_core): initialize in_trap when creating new threads. * thread.c (thread_join_m): raise ThreadError when running trap handler.Bug [#6416][ruby-core:44956] * test/ruby/test_thread.rb (test_thread_join_in_trap): new test for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37852 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-24* thread.c (thread_create_core): don't use th->thread_id beforekosaki
initialized. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20* vm_trace.c: add two methods:ko1
(1) TracePoint#return_value which returns return value on the :return and :c_return event. (2) TracePoint#raised_exception which returns raised exception value on the :raise event. Eeach methods raise RuntimeError if it is called at unsupported event. Please review and give us feedback until next preview release (Dec/2012) of Ruby 2.0.0. * insns.def, vm.c, vm_eval.c, vm_insnhelper.c, eval.c, thread.c: ditto. * vm_trace.c, vm_core.h: move definition of rb_trace_arg_t from vm_trace.c to vm_core.h. Caller fills rb_trace_arg_t and pass the pointer of this variable. * test/ruby/test_settracefunc.rb: fix tests to test this change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-20revert r37730 kosaki
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c (rb_thread_s_check_interrupt): removed redundantkosaki
GET_THREAD(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c (rb_threadptr_async_errinfo_active_p): added a smallkosaki
comment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c, vm_core.h: big rename th to cur_th when works onlykosaki
th is current thread. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c (rb_thread_blocking_region_end): replaced GET_THREAD()kosaki
with ruby_thread_from_native(). We don't have GVL here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c (rb_threadptr_execute_interrupts) removed.kosaki
* thread.c (rb_threadptr_execute_interrupts_common) renamed to rb_threadptr_execute_interrupts. I.e. unified rb_threadptr_execute_interrupts and rb_threadptr_execute_interrupts_common. * thread.c (rb_thread_schedule, rb_thread_execute_interrupts) s/_common//. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* prelude.rb: Moved Mutex#synchronize tokosaki
* thread.c (rb_mutex_synchronize_m): here. [Bug #4266] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37724 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-19* thread.c: add `Thread#backtrace_locations' method.ko1
This method is similart to `caller_locations' method for specific method. And fix to accept `level' and `n' parameters for `Thread#backtrace' and `Thread#backtrace_locations'. `caller' (and `caller_locations') do not return `caller' method frame. However, `Thread#backtrace' (and `Thread#backtrace_locations') return `Thread#backtrace' method frame itself if `Thread.current.backtrace' was called. * vm_backtrace.c: ditto. * internal.h: ditto. * test/ruby/test_backtrace.rb: add tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-16* thread.c (rb_thread_call_without_gvl2): change the parameter ofko1
`func' from `int *skip_interrupt' to `VALUE *flags'. If (flags & RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS) is not zero, then skip checking interrupt. [ruby-core:46547] * include/ruby/thread.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-01suppress warning: 'val' may be used uninitialized in this functionnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-31* thread.c (rb_thread_call_without_gvl2): Note that ubf() may or maydrbrain
not be called with the GVL. Hinted that rb_thread_call_with_gvl() can be used to access ruby functionality. [ruby-trunk - #6433] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-31* thread.c (rb_thread_call_without_gvl2): Update documentation todrbrain
natural English. * thread.c (rb_thread_call_with_gvl): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-29* thread.c: added Thread#thread_variable_(get|set),tenderlove
Thread#thread_variable?, and Thread#thread_variables for operating on variables that are local to threads. [ruby-core:47790] * vm.c: ditto * test/ruby/test_thread.rb: tests for thread variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23* thread.c (thread_raise_m): check interrupts after Thread#raiseko1
if a target thread is the current thread because the behavior of Thread.current.raise is expected to perform same as Kernel.raise (by rubyspec). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23Revert the last commit because some tests (in btest) failko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23* thread.c (rb_threadptr_raise): check interrupts afterko1
Thread#raise because the behavior of Thread.current.raise is expected to perform same as Kernel.raise (by rubyspec). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-16* thread.c (rb_threadptr_interrupt_mask): fix to check interruptko1
after interrupt_mask changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-06* thread.c (rb_thread_aref):zzak
Grammar in Thread documentation. Patch by Steve Klabnik [ruby-dev:47799] [Bug #7099] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-10thread.c: staticnobu
* thread.c (patrol_thread): should be static. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36947 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-09-09* thread.c (rb_mutex_lock): stop multiple threads usekosaki
pthread_cond_timedwait() concurrently. [Bug #6278] [ruby-core:44275] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36926 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-20vm_insnhelper.c: iclass as klass in cfpnobu
* vm_insnhelper.c (vm_call_method): follow iclasses as klass in cfp but not included modules. [ruby-core:47241] [Bug #6891] * vm_insnhelper.c (vm_call_bmethod): pass defined_class to follow proper ancestors. [ruby-core:47241] [Bug #6891] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-16* vm_trace.c, vm_core.h: simplify tracing mechanism.ko1
(1) add rb_hook_list_t data structure which includes hooks, events (flag) and `need_clean' flag. If the last flag is true, then clean the hooks list. In other words, deleted hooks are contained by `hooks'. Cleanup process should run before traversing the list. (2) Change check mechanism See EXEC_EVENT_HOOK() in vm_core.h. (3) Add `raw' hooks APIs Normal hooks are guarded from exception by rb_protect(). However, this protection is overhead for too simple functions which never cause exceptions. `raw' hooks are executed without protection and faster. Now, we only provide registration APIs. All `raw' hooks are kicked under protection (same as normal hooks). * include/ruby/ruby.h: remove internal data definition and macros. * internal.h (ruby_suppress_tracing), vm_trace.c: rename ruby_suppress_tracing() to rb_suppress_tracing() and remove unused function parameter. * parse.y: fix to use renamed rb_suppress_tracing(). * thread.c (thread_create_core): no need to set RUBY_VM_VM. * vm.c (mark_event_hooks): move definition to vm_trace.c. * vm.c (ruby_vm_event_flags): add a global variable. This global variable represents all of Threads and VM's event masks (T1#events | T2#events | ... | VM#events). You can check the possibility kick trace func or not with ruby_vm_event_flags. ruby_vm_event_flags is maintained by vm_trace.c. * cont.c (fiber_switch, rb_cont_call): restore tracing status. [Feature #4347] * test/ruby/test_continuation.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-15* vm_trace.c: separate trace_func related functions fromko1
thread.c. * thread.c: ditto. * common.mk: add vm_trace.o. * inits.c: call Init_vm_trace(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-29* thread.c (thread_create_core): hide th->async_errinfo_mask_stack fromnagachika
ObjectSpace.each_object. refix of r36539. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36570 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-29* thread.c (Init_Thread): does not need to set klassktsj
explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-07-25* thread.c (thread_create_core, Init_Thread): hidenagachika
th->async_errinfo_queue and th->async_errinfo_mask_stack from ObjectSpace.each_object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e