summaryrefslogtreecommitdiff
path: root/thread_pthread.h
AgeCommit message (Collapse)Author
2018-08-28thread_pthread.h: rename `gvl.acquired' to `gvl.owner' and documentnormal
`acquired' was an old boolean variable, but nowadays it is a rb_thread_t pointer; "gvl.owner" seems like a more appropriate name. And document the contended path including waitq, timer, and timer_err. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-19thread_pthread.c: reset timeslice delay when uncontendednormal
This matches the behavior of old timer thread more closely and seems to fix [Bug #14999] when limited to a single CPU. I cannot reproduce the error on a multi-core system unless I use schedtool to force affinity to a single CPU: schedtool -a 0x01 -e make test-spec \ MSPECOPT='-R1000 spec/ruby/library/conditionvariable/wait_spec.rb' While it may be good enough to pass the spec, I don't have huge degree of confidence in the interrupt handling robustness under extremely heavy load (these may be ancient bugs, though). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64467 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-15thread_pthread.h (native_thread_data): split list_node between ubf and gvlnormal
Do not waste extra memory for each thread, but make thread_pthread.c easier-to-follow as a result. [ruby-core:88475] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64375 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-13thread_pthread.c: eliminate timer thread by restructuring GVLnormal
This reverts commit 194a6a2c68e9c8a3536b24db18ceac87535a6051 (r64203). Race conditions which caused the original reversion will be fixed in the subsequent commit. [ruby-core:88360] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-06thread_pthread.c: restore timer-thread for now :<normal
[ruby-core:88306] Revert "process.c: ensure th->interrupt lock is held when migrating" This reverts commit 5ca416bdf6b6785cb20f139c2c514eda005fe42f (r64201) Revert "process.c (rb_waitpid): reduce sigwait_fd bouncing" This reverts commit 217bdd776fbeea3bfd0b9324eefbfcec3b1ccb3e (r64200). Revert "test/ruby/test_thread.rb (test_thread_timer_and_interrupt): add timeouts" This reverts commit 9f395f11202fc3c7edbd76f5aa6ce1f8a1e752a9 (r64199). Revert "thread_pthread.c (native_sleep): reduce ppoll sleeps" This reverts commit b3aa256c4d43d3d7e9975ec18eb127f45f623c9b (r64193). Revert "thread.c (consume_communication_pipe): do not retry after short read" This reverts commit 291a82f748de56e65fac10edefc51ec7a54a82d4 (r64185). Revert "test/ruby/test_io.rb (test_race_gets_and_close): timeout each thread" This reverts commit 3dbd8d1f66537f968f0461ed8547460b3b1241b3 (r64184). Revert "thread_pthread.c (gvl_acquire_common): persist timeout across calls" This reverts commit 8c2ae6e3ed072b06fc3cbc34fa8a14b2acbb49d5 (r64165). Revert "test/ruby/test_io.rb (test_race_gets_and_close): use SIGABRT on timeout" This reverts commit 931cda4db8afd6b544a8d85a6815765a9c417213 (r64135). Revert "thread_pthread.c (gvl_yield): do ubf wakeups when uncontended" This reverts commit 508f00314f46c08b6e9b0141c01355d24954260c (r64133). Revert "thread_pthread.h (native_thread_data): split condvars on some platforms" This reverts commit a038bf238bd9a24bf1e1622f618a27db261fc91b (r64124). Revert "process.c (waitpid_nogvl): prevent conflicting use of sleep_cond" This reverts commit 7018acc946882f21d519af7c42ccf84b22a46b27 (r64117). Revert "thread_pthread.c (rb_sigwait_sleep): th may be 0 from MJIT" This reverts commit 56491afc7916fb24f5c4dc2c632fb93fa7063992 (r64116). Revert "thread*.c: waiting on sigwait_fd performs periodic ubf wakeups" This reverts commit ab47a57a46e70634d049e4da20a5441c7a14cdec (r64115). Revert "thread_pthread.c (gvl_destroy): make no-op on GVL bits" This reverts commit 95cae748171f4754b97f4ba54da2ae62a8d484fd (r64114). Revert "thread_pthread.c (rb_sigwait_sleep): fix uninitialized poll set in UBF case" This reverts commit 4514362948fdb914c6138b12d961d92e9c0fee6c (r64113). Revert "thread_pthread.c (rb_sigwait_sleep): re-fix [Bug #5343] harder" This reverts commit 26b8a70bb309c7a367b9134045508b5b5a580a77 (r64111). Revert "thread.c: move ppoll wrapper into thread_pthread.c" This reverts commit 3dc7727d22fecbc355597edda25d2a245bf55ba1 (r64110). Revert "thread.c: move ppoll wrapper before thread_pthread.c" This reverts commit 2fa1e2e3c3c5c4b3ce84730dee4bcbe9d81b8e35 (r64109). Revert "thread_pthread.c (ubf_select): refix [Bug #5343]" This reverts commit 4c1ab82f0623eca91a95d2a44053be22bbce48ad (r64108). Revert "thread_win32.c: suppress warnings by -Wsuggest-attribute" This reverts commit 6a9b63e39075c53870933fbac5c1065f7d22047c (r64159). Revert "thread_pthread: remove timer-thread by restructuring GVL" This reverts commit 708bfd21156828526fe72de2cedecfaca6647dc1 (r64107). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-30thread_pthread.h (native_thread_data): split condvars on some platformsnormal
Maybe some platforms have strange condition variable implementations which have a "memory" of which mutexes they're associated with. In any case, it makes documentation easier even on GNU/Linux and FreeBSD. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64124 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-29thread_pthread: remove timer-thread by restructuring GVLnormal
To reduce resource use and reduce CI failure; remove timer-thread. Single-threaded Ruby processes (including forked children) will never see extra thread overhead. This prevents glibc and jemalloc from going into multi-threaded mode and initializing locks or causing fragmentation via arena explosion. The GVL is implements its own wait-queue as a ccan/list to permit controlling wakeup order. Timeslice under contention is handled by a designated timer thread (similar to choosing a "patrol_thread" for current deadlock checking). There is only one self-pipe, now, as wakeups for timeslice are done independently using condition variables. This reduces FD pressure slightly. Signal handling is handled directly by a Ruby Thread (instead of timer-thread) by exposing signal self-pipe to callers of rb_thread_fd_select, native_sleep, rb_wait_for_single_fd, etc... Acquiring, using, and releasing the self-pipe is exposed via 4 new internal functions: 1) rb_sigwait_fd_get - exclusively acquire timer_thread_pipe.normal[0] 2) rb_sigwait_fd_sleep - sleep and wait for signal (and no other FDs) 3) rb_sigwait_fd_put - release acquired result from rb_sigwait_fd_get 4) rb_sigwait_fd_migrate - migrate signal handling to another thread after calling rb_sigwait_fd_put. rb_sigwait_fd_migrate is necessary for waitpid callers because only one thread can wait on self-pipe at a time, otherwise a deadlock will occur if threads fight over the self-pipe. TRAP_INTERRUPT_MASK is now set for the main thread directly in signal handler via rb_thread_wakeup_timer_thread. Originally, I wanted to use POSIX timers (timer_create/timer_settime) for this. Unfortunately, this proved unfeasible as Mutex#sleep resumes on spurious wakeups and test/thread/test_cv.rb::test_condvar_timed_wait failed. Using pthread_sigmask to mask out SIGVTALRM fixed that test, but test/fiddle/test_function.rb::test_nogvl_poll proved there'd be some unavoidable (and frequent) incompatibilities from that approach. Finally, this allows us to drop thread_destruct_lock and interrupt current ec directly. We don't need to rely on vm->thread_destruct_lock or a coherent vm->running_thread on any platform. Separate timer-thread for time slice and signal handling is relegated to thread_win32.c, now. [ruby-core:88088] [Misc #14937] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-04-22thread*: all condvars are monotonicnormal
There's no reason to use CLOCK_REALTIME for any condvars in Ruby. Indeed, we initialized all condvars with RB_CONDATTR_CLOCK_MONOTONIC anyway; so simplify our code and reduce ifdefs. [ruby-core:85639] [Misc #14497] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-30* thread_pthread.c (register_ubf_list): renamed fromkosaki
add_signal_thread_list. * thread_pthread.c (unregister_ubf_list): renamed from remove_signal_thread_list. * thread_pthread.c (ubf_wakeup_all_threads): renamed from ping_signal_thread_list. * thread_pthread.c (ubf_wakeup_thread): renamed from ubf_select_each. * thread_pthread.c (ubf_threads_empty): renamed from check_signal_thread_list(). * thread_pthread.c (ubf_list_lock): renamed from signal_thread_list_lock. * thread_pthread.c (register_ubf_list): large simplification by using ccan/list.h. bonus: removed malloc() and exit(EXIT_FAILURE). * thread_pthread.c (unregister_ubf_list): ditto. * thread_pthread.c (ubf_threads_empty): ditto. * thread_pthread.c (ubf_wakeup_all_threads): ditto. * thread_pthread.c (print_signal_list): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-08-15thread_pthread: prefer rb_nativethread* types/functionsnormal
This will make it easier for us to try alternative mutex/condvar implementations while still using pthreads for thread management. [Feature #10134] * thread_pthread.h: define RB_NATIVETHREAD_LOCK_INIT and RB_NATIVETHREAD_COND_INIT macros * thread_pthread.c (native_mutex_lock, native_mutex_unlock, native_mutex_trylock, native_mutex_initialize, native_mutex_destroy, native_cond_wait): use rb_nativethread_lock_t instead of pthread_mutex_t * thread_pthread.c (native_mutex_debug): make argument type-agnostic to avoid later cast. * thread_pthread.c (register_cached_thread_and_wait): replace PTHREAD_COND_INITIALIZER with RB_NATIVETHREAD_COND_INIT, use native_mutex_{lock,unlock} * thread_pthread.c (use_cached_thread): use native_mutex_{lock,unlock} * thread_pthread.c (native_sleep): use rb_nativethread_lock_t to match th->interrupt_lock, use native_mutex_{lock,unlock} * thread_pthread.c (timer_thread_lock): use rb_nativethread_lock_t type git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-08thread_pthread.h: do not expose pthread type for locknormal
* thread_pthread.h (struct rb_global_vm_lock_struct): do not expose pthread type for lock git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-07-08thread_pthread.h: remove unneeded semaphore.h includenormal
* thread_pthread.h: remove unneeded semaphore.h include We currently do not use POSIX semaphores. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2014-05-14* ext/openssl/depend: remove dependency from internal headers.ko1
[Feature #9612] * ext/openssl/ossl.c (ossl_fips_mode_set): ditto. * ext/coverage/depend: ditto. * include/ruby/thread_native.h: added. This header file only provides wrapper functions to control native threads. These wrapper functions are used by MRI implementation. * vm_core.h: use include/ruby/thread_native.h. * thread.c: ditto. * thread_pthread.h: ditto. * thread_win32.h: ditto. * thread_native.h: removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23* thread_(pthread|win32).h: rename rb_thread_cond_t toko1
rb_nativethread_cond_t. * thread.c, thread_pthread.c, thread_win32.c, vm_core.h: catch up renaming. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23* thread_pthread.h, thread_win32.h: rename rb_thread_id_t toko1
rb_nativethread_id_t. * thread_pthread.c, vm_core.h: use rb_nativethread_id_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-07-23* thread_native.h: added.ko1
Move native thread related lines from vm_core.h. And declare several functions "rb_nativethread_lock_*", manipulate locking. * common.mk: add thread_native.h. * thread.c: add functions "rb_nativethread_lock_*". * thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t to rb_nativethread_lock_t to make it clear that this lock is for native thraeds, not for ruby threads. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-10-29* thread_pthread.h: no Structured Exception Handling like macros.nobu
[ruby-core:40432] [Bug #5491] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-27* thread_pthread.h (rb_global_vm_lock_struct): add volatile tokosaki
gvl->waiting. now thread_timer() access it w/o lock. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-16* thread_pthread.c, thread_pthread.h: remove unused variables.ko1
(native_thread_data_t::gvl_cond, native_thread_data_t::gvl_next) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32136 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-14* thread_pthread.c (gvl_yield): fix live lock issue on 1-2 cpuskosaki
system. It's additional fix for r32021. * thread_pthread.c (gvl_init): add switch_wait_cond. * thread_pthread.h (typedef struct rb_global_vm_lock_struct): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32091 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-13* thread_pthread.c: rewrite GVL completely.kosaki
* thread_win32.c: ditto. * thread_pthread.h: ditto. * vm_core.h: ditto. * thread.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-07* thread_pthread.c (USE_MONOTONIC_COND): check the availabilitynobu
more strictly. * thread_pthread.h (rb_thread_cond_t): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31462 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-06* thread_pthread.h (rb_thread_cond_t): add clockid field. it'skosaki
no longer an alias of pthread_cond_t. * thread_pthread.c: adapt new rb_thread_cond_t type. * thread.c (mutex_alloc): ditto. * thread_win32.c (native_cond_initialize): ditto. * configure.in: add check for pthread_cond_attr_setclock() and clockid_t type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-11-27* thread.c, vm_core.h: make gvl_acquire/release/init/destructko1
APIs to modularize GVL implementation. * thread_pthread.c, thread_pthread.h: Two GVL implementations. (1) Simple locking GVL which is same as existing GVL. (2) Wake-up queued threads. The wake-up order is simple FIFO. (We can make several queues to support exact priorities, however this causes some issues such as priority inversion and so on.) This impl. prevents spin-loop (*1) caused on SMP environemnts. *1: Only one Ruby thread acqures GVL again and again. Bug #2359 [ruby-core:26694] * thread_win32.c, thread_win32.h: Using simple lock not by CRITICAL_SECTION but by Mutex. Bug #3890 [ruby-dev:42315] * vm.c (ruby_vm_destruct): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29956 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-02-04* thread_pthread.c (native_thread_init_stack): use get_stack.naruse
patched by KOSAKI Motohiro [ruby-dev:40309] * thread_pthread.c (ruby_init_stack): use get_stack on platforms which have pthread_attr_get_np. (FreeBSD, DragonFlyBSD and NetBSD) This is because FreeBSD and DragonFly BSD must use pthread_attr_get_np to get stack size of main thread, but Mac OS X and Linux with LinuxThreads must use getrlimit. <http://www.nminoru.jp/~nminoru/programming/stackoverflow_handling.html> <http://d.hatena.ne.jp/nurse/20100204> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-18* eval_intern.h, insnhelper.h, thread_pthread.h, vm_core.h, vm_opts.h:nobu
prefixed include guards with RUBY. * id.h: added include guard. * regenc.h, regint.h, regparse.h: prefixed include guards with ONIGURUMA. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-01-06* $Date$ keyword removed to avoid inclusion of locale dependentakr
string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-12-25* thread_pthread.c, thread_pthread.h, thread_win32.c,ko1
thread_win32.c: make some functions static functions. a patch from Tadashi Saito <shiba AT mail2.accsnet.ne.jp> in [ruby-core:14407] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14657 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-13* blockinlining.c, compile.c, compile.h, debug.c, debug.h,ko1
id.c, insnhelper.h, insns.def, thread.c, thread_pthread.ci, thread_pthread.h, thread_win32.ci, thread_win32.h, vm.h, vm_dump.c, vm_evalbody.ci, vm_opts.h: fix comments and copyright year. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13920 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-27* thread.c: fix Mutex to be interruptable lock.ko1
* thread_win32.ci, thread_win32.h, thread_pthread.ci, thread_pthread.h: prepare native_cond_*() which are based on pthread_cond_*() spec. * prelude.rb: fix Mutex#synchronize method. * vm_core.h, include/ruby/intern.h: change unblock function interface (to pass some user data). * file.c, process.c: ditto. * benchmark/bm_vm2_mutex.rb: add a benchmark for mutex. * benchmark/bm_vm3_thread_mutex.rb: add a benchmark for mutex with contension. * benchmark/run.rb: fix to remove ENV['RUBYLIB'] for matzruby. * test/ruby/test_thread.rb: add a test. * common.mk: fix benchmark options. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08* thread.c, thread_pthread.ci, thread_win32.ci (thread_start_func_1):ko1
move cleanup function to thread_start_func_2(). * thread.c, thread_pthread.ci, thread_win32.ci: add more destruct functions. (native_thread_destroy() and native_mutex_destroy()) * thread_pthread.ci, thread_pthread.h: make native_mutex_* functions (check error, etc), it's not macro any more. * thread_win32.ci (thread_start_func_1): store some values before running thread (to release these after running thread). * thread_win32.ci (native_thread_create): fix spaces. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-06* blockinlining.c, compile.c, compile.h, error.c, eval.c,ko1
eval_intern.h, eval_jump.h, eval_load.c, eval_method.h, eval_safe.h, gc.c, insnhelper.h, insns.def, iseq.c, proc.c, process.c, signal.c, thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h, vm_dump.c, vm_evalbody.ci, vm_macro.def, yarv.h, yarvcore.h, yarvcore.c: change type and macro names: * yarv_*_t -> rb_*_t * yarv_*_struct -> rb_*_struct * yarv_tag -> rb_vm_tag * YARV_* -> RUBY_VM_* * proc.c, vm.c: move functions about env object creation from proc.c to vm.c. * proc.c, yarvcore.c: fix rb_cVM initialization place. * inits.c: change Init_ISeq() order (after Init_VM). * ruby.h, proc.c: change declaration place of rb_cEnv from proc.c to ruby.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-12-31 * Merge YARVko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e