summaryrefslogtreecommitdiff
path: root/thread_sync.c
Commit message (Collapse)AuthorAgeFilesLines
* Add WB_PROTECTED to mutexesJohn Hawthorn2021-09-171-1/+1
| | | | | | 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.
* Using RBOOL macroS.H2021-08-021-18/+7
|
* Distinguish signal and timeout [Bug #16608]Nobuyoshi Nakada2021-07-251-7/+11
|
* Replace copy coroutine with pthread implementation.Samuel Williams2021-07-011-47/+38
|
* Prefer qualified names under ThreadNobuyoshi Nakada2021-06-291-49/+49
|
* Refined define_thread_classNobuyoshi Nakada2021-06-281-4/+4
| | | | | | | Reduce duplications * ID caluculations of the same name * checks against the same name * registration to the root module hash
* Adjust styles [ci skip]Nobuyoshi Nakada2021-06-171-3/+7
| | | | | | | | | * --braces-after-func-def-line * --dont-cuddle-else * --procnames-start-lines * --space-after-for * --space-after-if * --space-after-while
* Convert initial contents before allocating queue bufferNobuyoshi Nakada2021-06-151-2/+4
|
* Properly convert time_t [Bug #17645]Nobuyoshi Nakada2021-03-141-1/+1
|
* --dont-cuddle-else [ci skip]Nobuyoshi Nakada2021-03-141-5/+10
|
* Thread::Queue.new should accept an Enumerable [Feature #17327]Nobuyoshi Nakada2021-02-121-1/+1
| | | | Enumerable implements #to_a but not #to_array.
* The Queue constructor should take an initial set of objectsChris Seaton2021-02-111-3/+15
| | | | Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
* Expose scheduler as public interface & bug fixes. (#3945)Samuel Williams2021-02-091-10/+10
| | | | | | | | | * 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.
* [DOC] Fixed indent [ci skip]Nobuyoshi Nakada2021-01-141-1/+1
|
* Proposed method for dealing with stack locals which have non-local lifetime.Samuel Williams2020-12-051-44/+51
|
* strip trailing spaces and adjusted indents [ci skip]Nobuyoshi Nakada2020-11-121-1/+1
|
* Tidy up book keeping for `thread->keeping_mutexes`.Samuel Williams2020-11-081-18/+35
| | | | | | 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.
* Don't try to resume blocked fiber on dead thread.Samuel Williams2020-11-081-5/+5
|
* Rename to `Fiber#set_scheduler`.Samuel Williams2020-11-071-3/+3
|
* Make `Thread#join` non-blocking.Samuel Williams2020-09-211-1/+1
|
* Remove from waiter in Mutex#lock with ensure when calling rb_scheduler_block()Benoit Daloze2020-09-201-6/+13
| | | | | * 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().
* Fix copy/paste error from 5bb5e706f1d310a467075630145d2cc277045765Benoit Daloze2020-09-181-1/+1
|
* Only interrupt when there is no scheduler in sync_wakeup()Benoit Daloze2020-09-181-2/+4
| | | | | | | | * 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
* Cleanup commented codeBenoit Daloze2020-09-171-4/+0
| | | | * Mutex operations no longer disable the Fiber scheduler.
* Add missing goto found;Benoit Daloze2020-09-171-0/+1
| | | | | * To still remove the lock from the Thread's list of acquired locks. * Also to not wake up other waiters and preserve blocking behavior.
* Fix Mutex#unlock with a scheduler and thread contentionBenoit Daloze2020-09-171-13/+13
| | | | * It would hit "[BUG] unexpected THREAD_STOPPED" before.
* Call scheduler.block instead of scheduler.kernel_sleep for blocking ↵Benoit Daloze2020-09-171-5/+5
| | | | | | | Queue/SizedQueue operations * scheduler.unblock was already already called before but with no corresponding scheduler.block * add test that Queue#pop makes the scheduler wait until it gets an element.
* Rename scheduler.{mutex_lock,mutex_unlock} to {block,unblock}Benoit Daloze2020-09-171-3/+3
| | | | * Move #kernel_sleep next to #block as it is similar
* Add support for Queue & SizedQueue.Samuel Williams2020-09-141-31/+39
|
* Add support for ConditionVariable.Samuel Williams2020-09-141-31/+44
|
* Improve handling of urgent notification pipe.Samuel Williams2020-09-141-45/+41
|
* Make Mutex per-Fiber instead of per-ThreadBenoit Daloze2020-09-141-37/+69
| | | | | | | | | * Enables Mutex to be used as synchronization between multiple Fibers of the same Thread. * With a Fiber scheduler we can yield to another Fiber on contended Mutex#lock instead of blocking the entire thread. * This also makes the behavior of Mutex consistent across CRuby, JRuby and TruffleRuby. * [Feature #16792]
* Introduce Ractor mechanism for parallel executionKoichi Sasada2020-09-031-5/+6
| | | | | | | | | | | | | | | | 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.
* rb_szqueue_push: do not goto into a branch卜部昌平2020-06-291-2/+1
| | | | | I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
* Thread scheduler for light weight concurrency.Samuel Williams2020-05-141-1/+6
|
* Added more NORETURN declarationsNobuyoshi Nakada2020-05-111-0/+1
|
* more on NULL versus functions.卜部昌平2020-02-071-1/+1
| | | | | | Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
* add assertion for mutex_lock.Koichi Sasada2019-10-281-5/+16
| | | | | After do_mutex_lock(mutex), the mutex should be owned by the current thread. Adding an assertion for this assumption.
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-1/+2
|
* fix arity of rb_mutex_synchronize_m卜部昌平2019-08-291-1/+1
| | | | | This is just a trivial mistake introduced in 6c56dae4b23c5c50e351758538141ca26b9aba40.
* rb_ensure now free from ANYARGS卜部昌平2019-08-271-1/+2
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_ensure, which also revealed many arity / type mismatches.
* do_mutex_lock: release mutex before checking for interrupts (fixes issue 15360)Neeraj Bhunwal2019-06-111-1/+5
|
* Use UNALIGNED_MEMBER_PTRNobuyoshi Nakada2019-05-311-1/+1
| | | | | | | | | | | * internal.h (UNALIGNED_MEMBER_ACCESS, UNALIGNED_MEMBER_PTR): moved from eval_intern.h. * compile.c iseq.c, vm.c: use UNALIGNED_MEMBER_PTR for `entries` in `struct iseq_catch_table`. * vm_eval.c, vm_insnhelper.c: use UNALIGNED_MEMBER_PTR for `body` in `rb_method_definition_t`.
* thread_sync.c (rb_mutex_t): eliminate fork_gennormal2018-12-221-40/+1
| | | | | | | | | | | | | | | | | | The true bug fork_gen was hiding was rb_mutex_abandon_locking_mutex failing to unconditionally clear the waitq of mutexes it was waiting on. So we fix rb_mutex_abandon_locking_mutex, instead, and eliminate rb_mutex_cleanup_keeping_mutexes. This commit was tested heavily on a single-core Pentium-M which was my most reliable reproducer of the "crash.rb" script from [Bug #15383] [Bug #14578] [Bug #15383] Note: [Bug #15430] turned out to be an entirely different problem: RLIMIT_NPROC limit was hit on the CI VMs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66489 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_sync.c (rb_mutex_cleanup_keeping_mutexes): update fork_gennormal2018-12-211-0/+16
| | | | | | | | | | | ... when clearing waitq. Otherwise, we risk redundantly clearing valid waiters in future calls to `mutex_ptr`. Note: I am not sure if this fixes [Bug #15430], and even if it did, fork_gen is a belt-and-suspenders redundancy for [Bug #15383] which wastes one word for every Mutex object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66477 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_sync.c (rb_mutex_abandon_keeping_mutexes): remove unnecessary checknormal2018-12-211-3/+1
| | | | | | | | rb_mutex_abandon_all functions fine when passed a NULL value, so let the compiler deal with the complexity of the branch instead of the person reading the code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_sync.c (mutex_ptr): only reinitalize waitqueue at forknormal2018-12-181-2/+0
| | | | | | | | | | | | | | | Mutexes need to remain locked after forking. This fixes "[BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is locked by another thread" and should fix test_fork_while_parent_locked failures in CI [ruby-core:90581] [Bug #15424] [ruby-core:90595] [Bug #15430] Fixes: r66230 ("handle mutexes held by parent threads in children") git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Prefer rb_check_arity when 0 or 1 argumentsnobu2018-12-061-1/+1
| | | | | | | Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_sync.c (mutex_ptr): handle mutexes held by parent threads in childrennormal2018-12-051-0/+11
| | | | | | | | | | | | Mutexes may be held by threads which only exist in the parent process, so their waitqueues may be populated with references to other dead threads. We must reset them at fork. I am a moron for introducing this bug :< [ruby-core:90312] [Bug #15383] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66230 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add some missing documentation to Queue#{close|deq} [ci skip]marcandre2018-09-161-1/+3
| | | | | | | | Patch by Lars Kanis. [Fix GH-1949] * Describe the impact of Queue#close to Queue#deq . git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e