summaryrefslogtreecommitdiff
path: root/thread_sync.c
AgeCommit message (Collapse)Author
2024-02-12Replace assert with RUBY_ASSERT in thread_sync.cPeter Zhu
assert does not print the bug report, only the file and line number of the assertion that failed. RUBY_ASSERT prints the full bug report, which makes it much easier to debug.
2024-01-17Remove SizedQueue#freezeJeremy Evans
Queue#freeze uses the same C function, so SizedQueue#freeze can use that via normal method lookup.
2023-12-14[DOC] Adjust some new features wording/examples. (#9183)Victor Shepelev
* Reword Range#overlap? docs last paragraph. * Docs: add explanation about Queue#freeze * Docs: Add :rescue event docs for TracePoint * Docs: Enhance Module#set_temporary_name documentation * Docs: Slightly expand Process::Status deprecations * Fix MatchData#named_captures rendering glitch * Improve Dir.fchdir examples * Adjust Refinement#target docs
2023-10-12M:N thread scheduler for RactorsKoichi Sasada
This patch introduce M:N thread scheduler for Ractor system. In general, M:N thread scheduler employs N native threads (OS threads) to manage M user-level threads (Ruby threads in this case). On the Ruby interpreter, 1 native thread is provided for 1 Ractor and all Ruby threads are managed by the native thread. From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means 1 Ruby thread has 1 native thread. M:N scheduler change this strategy. Because of compatibility issue (and stableness issue of the implementation) main Ractor doesn't use M:N scheduler on default. On the other words, threads on the main Ractor will be managed with 1:1 thread scheduler. There are additional settings by environment variables: `RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor. Note that non-main ractors use the M:N scheduler without this configuration. With this configuration, single ractor applications run threads on M:1 thread scheduler (green threads, user-level threads). `RUBY_MAX_CPU=n` specifies maximum number of native threads for M:N scheduler (default: 8). This patch will be reverted soon if non-easy issues are found. [Bug #19842]
2023-09-27Make {Queue,SizedQueue}#freeze raise TypeErrorJeremy Evans
Fixes [Bug #17146]
2023-09-08Try default `gcc` 9.4.0 to see if it exhibits the same compiler bugs. (#8394)Samuel Williams
* Revert "Extract `do_mutex_lock_check_interrupts` to try and fix `ppc64le`. (#8393)" This reverts commit 5184b40dd4dc446660cd35c3e53896324e95b317. * .travis.yml: Try default gcc 9.4.0 instead of gcc-10 in ppc64le and s390x. Use gcc 9.4.0 instead of gcc-10 to avoid the current failures by a possible GCC 10 compiler bug in the Travis ppc64le and s390x cases. And it also aligns with RubyCI Ubuntu ppc64le and s390x where the default gcc is used. --------- Co-authored-by: Jun Aruga <jaruga@ruby-lang.org> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-09-08Extract `do_mutex_lock_check_interrupts` to try and fix `ppc64le`. (#8393)Samuel Williams
We found some tests were hanging in `do_mutex_lock`, specifically the fiber scheduler autoload test. After much investigation, it may be a code generation bug. Because we didn't change the code, but only extracted it into a separate function, and it appears to fix the problem. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-07-13[DOC] Add parenthetical to explain what FIFO abbrev meansShane Becker
Notes: Merged: https://github.com/ruby/ruby/pull/8062
2023-07-13[DOC] Fix example code indentation from 3 to 2Shane Becker
Notes: Merged: https://github.com/ruby/ruby/pull/8063
2023-03-07Correctly clean up `keeping_mutexes` before resuming any other threads. (#7460)Samuel Williams
It's possible (but very rare) to have a race condition between setting `mutex->fiber = NULL` and `thread_mutex_remove(th, mutex)` which results in the following bug: ``` [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked ``` Fixes <https://bugs.ruby-lang.org/issues/19480>. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-02-08Replace `PACKED_STRUCT` and `PACKED_STRUCT_UNALIGNED`Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7268
2023-01-21Add `queue_list` and `szqueue_list` macrosNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7161
2023-01-19Fix compilation warnings in thread_sync.cPeter Zhu
Fixes the following compilation warnings: thread_sync.c:908:48: warning: taking address of packed member of `struct rb_queue` may result in an unaligned pointer value [-Waddress-of-packed-member] thread_sync.c:1181:48: warning: taking address of packed member of `struct rb_queue` may result in an unaligned pointer value [-Waddress-of-packed-member]
2023-01-18Don't redefine RB_OBJ_WRITEPeter Zhu
RB_OBJ_WRITE already exists in rgengc.h, so we shouldn't redefine it in gc.h. Notes: Merged: https://github.com/ruby/ruby/pull/7131
2022-11-09mutex: Raise a ThreadError when detecting a fiber deadlock (#6680)Jean byroot Boussier
[Bug #19105] If no fiber scheduler is registered and the fiber that owns the lock and the one that try to acquire it both belong to the same thread, we're in a deadlock case. Co-authored-by: Jean Boussier <byroot@ruby-lang.org> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-20Avoid missed wakeup with fiber scheduler and Fiber.blocking. (#6588)Samuel Williams
* Ensure that blocked fibers don't prevent valid wakeups. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2022-10-18Adjust indents [ci skip]Nobuyoshi Nakada
2022-10-17thread_sync.c: Clarify and document the behavior of timeout == 0Jean Boussier
[Feature #18982] Instead of introducing an `exception: false` argument to have `non_block` return nil rather than raise, we can clearly document that a timeout of 0 immediately returns. The code is refactored a bit to avoid doing a time calculation in such case. Notes: Merged: https://github.com/ruby/ruby/pull/6500
2022-08-18Implement SizedQueue#push(timeout: sec)Jean Boussier
[Feature #18944] If both `non_block=true` and `timeout:` are supplied, ArgumentError is raised. Notes: Merged: https://github.com/ruby/ruby/pull/6207
2022-08-06Adjust styles [ci skip]Nobuyoshi Nakada
2022-08-04thread_sync.c: pass proper argument to queue_sleep in rb_szqueue_pushJean Boussier
When I removed the SizeQueue#push timeout from my PR, I forgot to update the `queue_sleep` parameters to be a `queue_sleep_arg`. Somehow this worked on most archs, but on Solaris/Sparc it would legitimately crash when trying to access the `timeout` and `end` members of the struct. Notes: Merged: https://github.com/ruby/ruby/pull/6213
2022-08-02Implement Queue#pop(timeout: sec)Jean Boussier
[Feature #18774] As well as `SizedQueue#pop(timeout: sec)` If both `non_block=true` and `timeout:` are supplied, ArgumentError is raised. Notes: Merged: https://github.com/ruby/ruby/pull/6185
2022-07-26Rename rb_ary_tmp_new to rb_ary_hidden_newPeter Zhu
rb_ary_tmp_new suggests that the array is temporary in some way, but that's not true, it just creates an array that's hidden and not on the transient heap. This commit renames it to rb_ary_hidden_new. Notes: Merged: https://github.com/ruby/ruby/pull/6180
2022-07-21Expand tabs [ci skip]Takashi Kokubun
[Misc #18891] Notes: Merged: https://github.com/ruby/ruby/pull/6094
2022-03-30Prefix ccan headers (#4568)Nobuyoshi Nakada
* 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> Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2021-12-15[DOC] Improve Thread::Queue.new docs [ci skip]Victor Shepelev
Notes: Merged: https://github.com/ruby/ruby/pull/5273 Merged-By: nobu <nobu@ruby-lang.org>
2021-11-28Suppress address-of-packed-member warning by gccNobuyoshi Nakada
2021-09-17Add WB_PROTECTED to mutexesJohn Hawthorn
mutex_mark is (basically) NULL, so we don't have any references to mark. This means we should safely be able to mark Mutex as WB_PROTECTED without changing anything else. Notes: Merged: https://github.com/ruby/ruby/pull/4852
2021-08-02Using RBOOL macroS.H
Notes: Merged: https://github.com/ruby/ruby/pull/4695 Merged-By: nobu <nobu@ruby-lang.org>
2021-07-25Distinguish signal and timeout [Bug #16608]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4256
2021-07-01Replace copy coroutine with pthread implementation.Samuel Williams
2021-06-29Prefer qualified names under ThreadNobuyoshi Nakada
2021-06-28Refined define_thread_classNobuyoshi Nakada
Reduce duplications * ID caluculations of the same name * checks against the same name * registration to the root module hash
2021-06-17Adjust styles [ci skip]Nobuyoshi Nakada
* --braces-after-func-def-line * --dont-cuddle-else * --procnames-start-lines * --space-after-for * --space-after-if * --space-after-while
2021-06-15Convert initial contents before allocating queue bufferNobuyoshi Nakada
2021-03-14Properly convert time_t [Bug #17645]Nobuyoshi Nakada
2021-03-14--dont-cuddle-else [ci skip]Nobuyoshi Nakada
2021-02-12Thread::Queue.new should accept an Enumerable [Feature #17327]Nobuyoshi Nakada
Enumerable implements #to_a but not #to_array.
2021-02-11The Queue constructor should take an initial set of objectsChris Seaton
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/4140 Merged-By: nobu <nobu@ruby-lang.org>
2021-02-09Expose scheduler as public interface & bug fixes. (#3945)Samuel Williams
* Rename `rb_scheduler` to `rb_fiber_scheduler`. * Use public interface if available. * Use `rb_check_funcall` where possible. * Don't use `unblock` unless the fiber was non-blocking. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2021-01-14[DOC] Fixed indent [ci skip]Nobuyoshi Nakada
2020-12-05Proposed method for dealing with stack locals which have non-local lifetime.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3624
2020-11-12strip trailing spaces and adjusted indents [ci skip]Nobuyoshi Nakada
2020-11-08Tidy up book keeping for `thread->keeping_mutexes`.Samuel Williams
When a scheduler is present, it's entirely possible for `th->keeping_mutexes` to be updated while enumerating the waitq. Therefore it must be fetched only during the removal operation. Notes: Merged: https://github.com/ruby/ruby/pull/3743
2020-11-08Don't try to resume blocked fiber on dead thread.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3743
2020-11-07Rename to `Fiber#set_scheduler`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3742
2020-09-21Make `Thread#join` non-blocking.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3558
2020-09-20Remove from waiter in Mutex#lock with ensure when calling rb_scheduler_block()Benoit Daloze
* Previously this could lead to an invalid waiter entry and then trying to wake up that waiter would result in various issues in rb_mutex_unlock_th().
2020-09-18Fix copy/paste error from 5bb5e706f1d310a467075630145d2cc277045765Benoit Daloze
2020-09-18Only interrupt when there is no scheduler in sync_wakeup()Benoit Daloze
* When there is a scheduler, the Fiber that would be blocked has already been rescheduled and there is no point to interrupt something else. That blocked Fiber will be rescheduled as the next call to the scheduler (e.g., IO, sleep, other blocking sync). * See discussion on https://github.com/ruby/ruby/commit/d01954632d