summaryrefslogtreecommitdiff
path: root/thread.c
AgeCommit message (Collapse)Author
2020-10-01Don't use `th->scheduler` directly because it's not always valid to do so.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3613
2020-10-01rb_thread_scheduler is no longer usedNobuyoshi Nakada
2020-10-01Remove `Thread.scheduler` from public interface.Samuel Williams
It's implementation is equivalent to: Thread.current.scheduler unless Thread.current.blocking? Notes: Merged: https://github.com/ruby/ruby/pull/3610
2020-09-21Make Thread#join always convert its argument, as before 70f08f1eedBenoit Daloze
2020-09-21Make it clear the first field of join_arg is the waiting threadBenoit Daloze
* And not some list of sort.
2020-09-21Make `Thread#join` non-blocking.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3558
2020-09-21When setting current thread scheduler to nil, invoke `#close`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3557
2020-09-17Call scheduler.block instead of scheduler.kernel_sleep for blocking ↵Benoit Daloze
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.
2020-09-15restart Ractor.select on intteruptKoichi Sasada
signal can interrupt Ractor.select, but if there is no exception, Ractor.select should restart automatically. Notes: Merged: https://github.com/ruby/ruby/pull/3534
2020-09-14Add support for Queue & SizedQueue.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-14Make Mutex per-Fiber instead of per-ThreadBenoit Daloze
* 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] Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-14Standardised scheduler interface.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-14Add `rb_thread_current_scheduler()`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3434
2020-09-11Removed Thread#safe_levelHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/3531
2020-09-10If the GC runs before the Mutex's are initialised then we get a crash in ↵Matt Valentine-House
pthread_mutex_lock. It is possible for GC to run during initialisation due to objects being allocated Notes: Merged: https://github.com/ruby/ruby/pull/3510
2020-09-03Introduce Ractor mechanism for parallel executionKoichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/3365
2020-08-17procnames-start-lines [ci skip]Nobuyoshi Nakada
2020-07-20Rename `rb_current_thread_scheduler` to `rb_thread_scheduler_if_nonblocking`.Samuel Williams
Correctly capture thread before releasing GVL and pass as argument to `rb_thread_scheduler_if_nonblocking`. Notes: Merged: https://github.com/ruby/ruby/pull/3323
2020-06-29add UNREACHABLE_RETURN卜部昌平
Not every compilers understand that rb_raise does not return. When a function does not end with a return statement, such compilers can issue warnings. We would better tell them about reachabilities. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-29exec_recursive: do not goto into a branch卜部昌平
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor. Notes: Merged: https://github.com/ruby/ruby/pull/3247
2020-06-20compile.c: Improve branch coverage instrumentation [Bug #16967]Yusuke Endoh
Formerly, branch coverage measurement counters are generated for each compilation traverse of the AST. However, ensure clause node is traversed twice; one is for normal-exit case (the resulted bytecode is embedded in its outer scope), and the other is for exceptional case (the resulted bytecode is used in catch table). Two branch coverage counters are generated for the two cases, but it is not desired. This changeset revamps the internal representation of branch coverage measurement. Branch coverage counters are generated only at the first visit of a branch node. Visiting the same node reuses the already-generated counter, so double counting is avoided. Notes: Merged: https://github.com/ruby/ruby/pull/3240
2020-05-25Make Thread#thread_variable? similar to #thread_variable_getJeremy Evans
Don't use rb_check_id, which only works for pinned symbols. Switch inadvertent creation test for thread_variable? to only check for pinned symbols, same as thread_variable_get and thread_variable_set. Make key variable name in thread_local_set match thread_local_get and thread_variable?. Fixes [Bug #16906] Notes: Merged: https://github.com/ruby/ruby/pull/3145
2020-05-14Thread scheduler for light weight concurrency.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/3032 Merged-By: ioquatix <samuel@codeotaku.com>
2020-05-12Thread#backtrace may return nil [ci skip]Kazuhiro NISHIYAMA
2020-05-11sed -i 's|ruby/impl|ruby/internal|'卜部昌平
To fix build failures. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-05-11sed -i s|ruby/3|ruby/impl|g卜部昌平
This shall fix compile errors. Notes: Merged: https://github.com/ruby/ruby/pull/3079
2020-04-09should check pending interrupts correctly.Koichi Sasada
rb_uninterruptible() disables any interrupts using handle_interrupt feature (This function is used by `p`). After this function, pending interrupts should be checked correctly, however there is no chance to setup interrupt flag of working threads, it means that nobody checks pending interrupts. For example, it ignores terminate signal delivered at the end of main thread and program can't stop. This patch set interrupt flag if there are pending interrupts.
2020-04-08Merge pull request #2991 from shyouhei/ruby.h卜部昌平
Split ruby.h Notes: Merged-By: shyouhei <shyouhei@ruby-lang.org>
2020-03-26check flags passed to rb_nogvl()Koichi Sasada
RB_NOGVL_UBF_ASYNC_SAFE is wrongly specified because flags is not checked. [Bug #15499] 23444302
2020-02-20fix arity mismatch卜部昌平
This is a ruby method with arity zero. Which means, this function takes one argument (that is self).
2020-02-07more on NULL versus functions.卜部昌平
Function pointers are not void*. See also ce4ea956d24eab5089a143bba38126f2b11b55b6 8427fca49bd85205f5a8766292dd893f003c0e48
2020-01-11st_delete_wrap is no longer usedNobuyoshi Nakada
2020-01-11Let execution context local storage be an ID tableLourens Naudé
Notes: Merged: https://github.com/ruby/ruby/pull/2814
2020-01-02Fully separate positional arguments and keyword argumentsJeremy Evans
This removes the warnings added in 2.7, and changes the behavior so that a final positional hash is not treated as keywords or vice-versa. To handle the arg_setup_block splat case correctly with keyword arguments, we need to check if we are taking a keyword hash. That case didn't have a test, but it affects real-world code, so add a test for it. This removes rb_empty_keyword_given_p() and related code, as that is not needed in Ruby 3. The empty keyword case is the same as the no keyword case in Ruby 3. This changes rb_scan_args to implement keyword argument separation for C functions when the : character is used. For backwards compatibility, it returns a duped hash. This is a bad idea for performance, but not duping the hash breaks at least Enumerator::ArithmeticSequence#inspect. Instead of having RB_PASS_CALLED_KEYWORDS be a number, simplify the code by just making it be rb_keyword_given_p(). Notes: Merged: https://github.com/ruby/ruby/pull/2794
2019-12-28Fix typoKazuhiro NISHIYAMA
2019-12-26decouple internal.h headers卜部昌平
Saves comitters' daily life by avoid #include-ing everything from internal.h to make each file do so instead. This would significantly speed up incremental builds. We take the following inclusion order in this changeset: 1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very first thing among everything). 2. RUBY_EXTCONF_H if any. 3. Standard C headers, sorted alphabetically. 4. Other system headers, maybe guarded by #ifdef 5. Everything else, sorted alphabetically. Exceptions are those win32-related headers, which tend not be self- containing (headers have inclusion order dependencies). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26TIMESPEC_SEC_MAX might be bigger than 53 bits.卜部昌平
The same as 41bc766763dba63ae2529f2f9070b8e26399745c. Read that commit for what is happening. Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-26other minior internal header tweaks卜部昌平
These headers need no rewrite. Just add some minor tweaks, like addition of #include lines. Mainly cosmetic. TIMET_MAX_PLUS_ONE was deleted because the macro was used from only one place (directly write expression there). Notes: Merged: https://github.com/ruby/ruby/pull/2711
2019-12-16thread.c: avoid needless read after select|ppollEric Wong
We do not need to issue pipe|eventfd read(2) syscall unless select, ppoll|poll declares the FD needs reading.
2019-12-11Make Thread#to_s consistent with Method and Proc to_sJean byroot Boussier
Notes: Merged: https://github.com/ruby/ruby/pull/2738
2019-12-05move an interrupt point.Koichi Sasada
`args_ptr` can be corrupted by interrupt handlers. Pointed by nagachika <https://ruby-trunk-changes.hatenablog.com/entry/ruby_trunk_changes_20191204>.
2019-12-03Check interrupts before starting threadJeremy Evans
Fixes a hang when Thread.new calls Thread.new in a loop. Fixes [Bug #13688] Notes: Merged: https://github.com/ruby/ruby/pull/2715
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-04Use ident hash for top-level recursion checkJohn Hawthorn
We track recursion in order to not infinite loop in ==, inspect, and similar methods by keeping a thread-local 1 or 2 level hash. This allows us to track when we have seen the same object (ex. using inspect) or same pair of objects (ex. using ==) in this stack before and to treat that differently. Previously both levels of this Hash used the object's memory_id as a key (using object_id would be slow and wasteful). Unfortunately, prettyprint (pp.rb) uses this thread local variable to "pretend" to be inspect and inherit its same recursion behaviour. This commit changes the top-level hash to be an identity hash and to use objects as keys instead of their object_ids. I'd like to have also converted the 2nd level hash to an ident hash, but it would have prevented an optimization which avoids allocating a 2nd level hash for only a single element, which we want to keep because it's by far the most common case. So the new format of this hash is: { object => true } (not paired) { lhs_object => rhs_object_memory_id } (paired, single object) { lhs_object => { rhs_object_memory_id => true, ... } } (paired, many objects) We must also update pp.rb to match this (using identity hashes). Notes: Merged: https://github.com/ruby/ruby/pull/2644
2019-10-09Prefer st_is_member over st_lookup with 0Ben Woosley
The st_is_member DEFINE has simpler semantics, for more readable code. Notes: Merged: https://github.com/ruby/ruby/pull/1622
2019-10-09avoid overflow in integer multiplication卜部昌平
This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes. Notes: Merged: https://github.com/ruby/ruby/pull/2540
2019-09-26Add rb_adjust_argv_kw_splat to internal.hJeremy Evans
We are calling this in a few other files, it is better to have it in a header than adding prototypes to the other files. Notes: Merged: https://github.com/ruby/ruby/pull/2491
2019-09-27Check the argument sizeNobuyoshi Nakada
Ensure that argument array size does not overflow as `int`, before cast in thread_do_start after new thread created.
2019-09-26Fix shorten-64-to-32 compile warnings/errorsJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2484