summaryrefslogtreecommitdiff
path: root/thread_pthread.c
Commit message (Collapse)AuthorAgeFilesLines
* Adjust styles [ci skip]Nobuyoshi Nakada2022-07-271-1/+2
|
* Expand tabs [ci skip]Takashi Kokubun2022-07-211-177/+177
| | | | [Misc #18891]
* GVL Instrumentation: remove the EXITED count assertionJean Boussier2022-07-131-7/+2
| | | | | It's very flaky for some unknown reason. Something we have an extra EXITED event. I suspect some other test is causing this.
* thread_pthread.c: call SUSPENDED event when entering native_sleepJean Boussier2022-07-071-0/+2
| | | | | | | | | [Bug #18900] Thread#join and a few other codepaths are using native sleep as a way to suspend the current thread. So we should call the relevant hook when this happen, otherwise some thread may transition directly from `RESUMED` to `READY`.
* thread_pthread.c: Remove useless call to pthread_rwlock_initJean Boussier2022-07-061-6/+1
|
* GVL Instrumentation API: add STARTED and EXITED eventsJean Boussier2022-06-171-11/+14
| | | | | | | | [Feature #18339] After experimenting with the initial version of the API I figured there is a need for an exit event to cleanup instrumentation data. e.g. if you record data in a {thread_id -> data} table, you need to free associated data when a thread goes away.
* Remove unused rb_thread_create_mjit_threadTakashi Kokubun2022-06-151-34/+0
| | | | follow up https://github.com/ruby/ruby/pull/6006
* thread_pthread.c: trigger THREAD_EVENT_READY when going throuhg the fast path.Jean Boussier2022-06-071-4/+4
|
* [Feature #18339] GVL Instrumentation APIJean Boussier2022-06-031-1/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ref: https://bugs.ruby-lang.org/issues/18339 Design: - This tries to minimize the overhead when no hook is registered. It should only incur an extra unsynchronized boolean check. - The hook list is protected with a read-write lock as to cause contention when some hooks are registered. - The hooks MUST be thread safe, and MUST NOT call into Ruby as they are executed outside the GVL. - It's simply a noop on Windows. API: ``` rb_internal_thread_event_hook_t * rb_internal_thread_add_event_hook(rb_internal_thread_event_callback callback, rb_event_flag_t internal_event, void *user_data); bool rb_internal_thread_remove_event_hook(rb_internal_thread_event_hook_t * hook); ``` You can subscribe to 3 events: - READY: called right before attempting to acquire the GVL - RESUMED: called right after successfully acquiring the GVL - SUSPENDED: called right after releasing the GVL. The hooks MUST be threadsafe, as they are executed outside of the GVL, they also MUST NOT call any Ruby API.
* Support old Mac OS X SDK and gccNobuyoshi Nakada2022-05-271-2/+17
| | | | | | | | | | | | Follow up of https://github.com/ruby/ruby/pull/5927 `pthread_threadid_np()` is not even be declared in outdated SDKs. Also, the `__API_AVAILABLE` macro does not work on gcc, which does not support the [availability] attribute of clang, so an additional weak symbol declaration is required to check for weakly linked symbols. [availability]: https://clang.llvm.org/docs/AttributeReference.html#availability
* altstack is native thread's attrKoichi Sasada2022-05-241-2/+2
| | | | Move th->altstack to th->nt->altstack.
* remove `DEBUG_OUT()` macroKoichi Sasada2022-05-241-12/+0
| | | | This macro is no longer used ([GH-5933]).
* use `RUBY_DEBUG_LOG` instead of `thread_debug`Koichi Sasada2022-05-241-10/+12
| | | | | `thread_debug()` was introduced to print debug messages on `THREAD_DEBUG > 0` but `RUBY_DEBUG_LOG()` is more controllable.
* remove `NON_SCALAR_THREAD_ID` supportKoichi Sasada2022-05-241-6/+7
| | | | | | | | | `NON_SCALAR_THREAD_ID` shows `pthread_t` is non-scalar (non-pointer) and only s390x is known platform. However, the supporting code is very complex and it is only used for deubg print information. So this patch removes the support of `NON_SCALAR_THREAD_ID` and make the code simple.
* Support old Mac OS XNobuyoshi Nakada2022-05-231-0/+8
| | | | | `pthread_threadid_np` is available since Mac OS X 10.6, use `pthread_mach_thread_np` on older systems.
* Revert broken thread_pthread.c in 539459abda3Nobuyoshi Nakada2022-05-221-17/+4
|
* Ruby31: add support for Darwin ppc/ppc64 (#5927)Sergey Fedorov2022-05-221-4/+17
| | | | | | | | | * add coroutines for ppc & ppc64 * fix universal coroutine to include ppc & ppc64 * add powerpc*-darwin to configure.ac * fix thread_pthread for older systems
* Fix build if UBF_TIMER == UBF_TIMER_PTHREADJeremy Evans2022-04-221-1/+1
|
* introduce struct `rb_native_thread`Koichi Sasada2022-04-231-78/+84
| | | | | | | | | `rb_thread_t` contained `native_thread_data_t` to represent thread implementation dependent data. This patch separates them and rename it `rb_native_thread` and point it from `rb_thraed_t`. Now, 1 Ruby thread (`rb_thread_t`) has 1 native thread (`rb_native_thread`).
* rename thread internal namingKoichi Sasada2022-04-221-121/+145
| | | | | | | | | | | | | | | | | | | | | | | | Now GVL is not process *Global* so this patch try to use another words. * `rb_global_vm_lock_t` -> `struct rb_thread_sched` * `gvl->owner` -> `sched->running` * `gvl->waitq` -> `sched->readyq` * `rb_gvl_init` -> `rb_thread_sched_init` * `gvl_destroy` -> `rb_thread_sched_destroy` * `gvl_acquire` -> `thread_sched_to_running` # waiting -> ready -> running * `gvl_release` -> `thread_sched_to_waiting` # running -> waiting * `gvl_yield` -> `thread_sched_yield` * `GVL_UNLOCK_BEGIN` -> `THREAD_BLOCKING_BEGIN` * `GVL_UNLOCK_END` -> `THREAD_BLOCKING_END` * removed * `rb_ractor_gvl` * `rb_vm_gvl_destroy` (not used) There are GVL functions such as `rb_thread_call_without_gvl()` yet but I don't have good name to replace them. Maybe GVL stands for "Greate Valuable Lock" or something like that.
* fix to use `node.gvl` instead of `node.ubf`Koichi Sasada2022-04-141-1/+1
| | | | | | The last parameter of `ccan_list_top()` is to acquire the pointer of the top of element, so `node.ubf` is no problem. But this context it accesses gvl list, so `node.gvl` is better.
* Prefix ccan headers (#4568)Nobuyoshi Nakada2022-03-301-25/+25
| | | | | | | | | | | | | * Prefixed ccan headers * Remove unprefixed names in ccan/build_assert * Remove unprefixed names in ccan/check_type * Remove unprefixed names in ccan/container_of * Remove unprefixed names in ccan/list Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
* thread.c: put platform specific part in each impl fileYuta Saito2022-01-191-0/+7
|
* [Feature #18290] Remove all usages of rb_gc_force_recyclePeter Zhu2021-11-081-1/+1
| | | | | This commit removes usages of rb_gc_force_recycle since it is a burden to maintain and makes changes to the GC difficult.
* include/ruby/internal/interpreter.h: add doxygen卜部昌平2021-09-101-4/+0
| | | | | | | | Must not be a bad idea to improve documents. [ci skip] In fact many functions declared in the header file are already documented more or less. They were just copy & pasted, with applying some style updates.
* Suppress unused-variable warningsNobuyoshi Nakada2021-08-161-2/+2
|
* Replace copy coroutine with pthread implementation.Samuel Williams2021-07-011-2/+2
|
* POSIX timer cannot be shared in forked process [Bug #17941]Nobuyoshi Nakada2021-06-091-0/+1
|
* Make `Thread#native_thread_id` not-implemented if unsupportedNobuyoshi Nakada2021-06-011-4/+5
| | | | | Raise `NotImplementedError` on unsupported platforms regardless the argument consistently.
* Add Thread#native_thread_id [Feature #17853]NARUSE, Yui2021-05-261-0/+37
|
* Fix -Wundef warnings for patterns `#if HAVE`Benoit Daloze2021-05-041-2/+2
| | | | | | * See [Feature #17752] * Using this to detect them: git grep -P 'if\s+HAVE' | grep -Pv 'HAVE_LONG_LONG|/ChangeLog|HAVE_TYPEOF'
* add debug code for timer_posixKoichi Sasada2021-02-021-8/+47
| | | | | timer_posix mode is managed by timer_posix.state. This patch adds some debug code for the transition of the state.
* thread_pthread.c: pthread_kill is not available on emscriptenYusuke Endoh2021-01-231-1/+1
|
* introduce USE_VM_CLOCK for windows.Koichi Sasada2020-11-111-4/+8
| | | | | | | | | | | | | | | | The timer function used on windows system set timer interrupt flag of current main ractor's executing ec and thread can detect the end of time slice. However, to set all ec->interrupt_flag for all running ractors, it is requires to synchronize with other ractors. However, timer thread can not acquire the ractor-wide lock because of some limitation. To solve this issue, this patch introduces USE_VM_CLOCK compile option to introduce rb_vm_t::clock. This clock will be incremented by the timer thread and each thread can check the incrementing by comparison with previous checked clock. At last, on windows platform this patch introduces some overhead, but I think there is no critical performance issue because of this modification.
* Use language TLS specifier if it is possible.Koichi Sasada2020-10-201-0/+16
| | | | | | | To access TLS, it is faster to use language TLS specifier instead of using pthread_get/setspecific functions. Original proposal is: Use native thread locals. #3665
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-109/+117
| | | | | | | | | | | | | | | | This commit introduces Ractor mechanism to run Ruby program in parallel. See doc/ractor.md for more details about Ractor. See ticket [Feature #17100] to see the implementation details and discussions. [Feature #17100] This commit does not complete the implementation. You can find many bugs on using Ractor. Also the specification will be changed so that this feature is experimental. You will see a warning when you make the first Ractor with `Ractor.new`. I hope this feature can help programmers from thread-safety issues.
* Get rid of -Wgnu-folding-constant errorsNobuyoshi Nakada2020-05-011-5/+8
| | | | Also renamed as like as a constant.
* Fixed inverted current thread condition [Bug #16808]Nobuyoshi Nakada2020-04-231-1/+1
|
* Truncate too long thread name before setting [Bug #16808]Nobuyoshi Nakada2020-04-231-6/+30
|
* thread_pthread.c: allocate sigaltstack before pthread_createYusuke Endoh2020-03-061-1/+4
| | | | | | | | | | | | A new (not-initialized-yet) pthread attempts to allocate sigaltstack by using xmalloc. It may cause GC, but because the thread is not initialized yet, ruby_native_thread_p() returns false, which leads to "[FATAL] failed to allocate memory" and exit. In fact, we can observe the error message in the log of OpenBSD CI: https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20200306T083005Z.log.html.gz This changeset allocates sigaltstack before pthread is created.
* more on NULL versus functions.卜部昌平2020-02-071-1/+1
| | | | | | Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
* rb_thread_create now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_thread_create, which seems very safe to do.
* * expand tabs.git2019-06-191-2/+2
|
* Remove IA64 support.Samuel Williams2019-06-191-70/+5
|
* * remove trailing spaces, expand tabs.git2019-06-191-1/+1
|
* Fix handling of vm_stack_size and avoid trying to deallocate it.Samuel Williams2019-06-191-1/+1
|
* * expand tabs.git2019-05-251-17/+17
|
* Fix process not waking up on signals on OpenBSDJeremy Evans2019-05-241-12/+20
| | | | | | | | | | | | | | | | | | | | | When using UBF_TIMER_PTHREAD (the UBF handler on OpenBSD), the timer_pthread_fn function will not signal the main thread with SIGVTALRM in cases where timer_pthread is armed before consume_communication_pipe is called. This is because consume_communication_pipe will unarm the timer. Fix this by checking the return value of consume_communication_pipe. If it returns TRUE and the timer_pthread is disarmed, then signal the main thread with SIGVTALRM. On OpenBSD, this fixes TestThread#test_thread_timer_and_interrupt, and fixes hangs in TestProcess#test_execopts_redirect_open_fifo_interrupt_raise and TestProcess#test_execopts_redirect_open_fifo_interrupt_print. It also fixes the use of Ctrl+C/SIGINT in irb on OpenBSD. It does not cause any test failures on Linux when UBF_TIMER_PTHREAD is forced as the UBF handler. Fixes [Bug #15798]
* introduce rb_nogvl C-API to mark ubf as async-signal-safenormal2019-01-041-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | zlib and bignum both contain unblocking functions which are async-signal-safe and do not require spawning additional threads. We can execute those functions directly in signal handlers without incurring overhead of extra threads, so provide C-API users the ability to deal with that. Other C-API users may have similar need. This flexible API can supercede existing uses of rb_thread_call_without_gvl and rb_thread_call_without_gvl2 by introducing a flags argument to control behavior. Note: this API is NOT finalized. It needs approval from other committers. I prefer shorter name than previous rb_thread_call_without_gvl* functions because my eyes requires big fonts. [Bug #15499] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (call_without_gvl): spawn thread for UBF iff single-threadednormal2019-01-041-0/+19
| | | | | | | | | | | We need another native thread to call some unblocking functions which aren't RUBY_UBF_IO or RUBY_UBF_PROCESS. Instead of a permanent thread in <= 2.5, we can now rely on the thread cache feature to perform interrupts. [ruby-core:90865] [Bug #15499] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e