summaryrefslogtreecommitdiff
path: root/ractor.c
AgeCommit message (Collapse)Author
2020-11-02suppport Ractor.send(move: true) for more detaKoichi Sasada
This patch allows to move more data types. Notes: Merged: https://github.com/ruby/ruby/pull/3727
2020-10-31Ractor's "will" doesn't need copying.Koichi Sasada
`r = Ractor.new{ expr }` generates the block return value from `expr` and we can get this value by `r.take`. Ractor.yield and Ractor#take passing values by copying on default. However, the block return value (we named it "will" in the code) is not referred from the Ractor because the Ractor is already dead. So we can pass the reference of "will" to another ractor without copying. We can apply same story for the propagated exception. Notes: Merged: https://github.com/ruby/ruby/pull/3724
2020-10-30Ractor.make_shareable(a_proc)Koichi Sasada
Ractor.make_shareable() supports Proc object if (1) a Proc only read outer local variables (no assignments) (2) read outer local variables are shareable. Read local variables are stored in a snapshot, so after making shareable Proc, any assignments are not affeect like that: ```ruby a = 1 pr = Ractor.make_shareable(Proc.new{p a}) pr.call #=> 1 a = 2 pr.call #=> 1 # `a = 2` doesn't affect ``` [Feature #17284] Notes: Merged: https://github.com/ruby/ruby/pull/3722
2020-10-22refactoring obj_traverse_iKoichi Sasada
2020-10-21refactoring frozen_shareable_pKoichi Sasada
2020-10-21refactoring rb_obj_traverse()Koichi Sasada
* create rec check hash lazily * do not pass *data pointer for enter/leave function because it is not used. Notes: Merged: https://github.com/ruby/ruby/pull/3682
2020-10-21Ractor.make_shareable(obj)Koichi Sasada
Introduce new method Ractor.make_shareable(obj) which tries to make obj shareable object. Protocol is here. (1) If obj is shareable, it is shareable. (2) If obj is not a shareable object and if obj can be shareable object if it is frozen, then freeze obj. If obj has reachable objects (rs), do rs.each{|o| Ractor.make_shareable(o)} recursively (recursion is not Ruby-level, but C-level). (3) Otherwise, raise Ractor::Error. Now T_DATA is not a shareable object even if the object is frozen. If the method finished without error, given obj is marked as a sharable object. To allow makng a shareable frozen T_DATA object, then set `RUBY_TYPED_FROZEN_SHAREABLE` as type->flags. On default, this flag is not set. It means user defined T_DATA objects are not allowed to become shareable objects when it is frozen. You can make any object shareable by setting FL_SHAREABLE flag, so if you know that the T_DATA object is shareable (== thread-safe), set this flag, at creation time for example. `Ractor` object is one example, which is not a frozen, but a shareable object. Notes: Merged: https://github.com/ruby/ruby/pull/3678
2020-10-20Some global variables can be accessed from ractorsKoichi Sasada
Some global variables should be used from non-main Ractors. [Bug #17268] ```ruby # ractor-local (derived from created ractor): debug '$DEBUG' => $DEBUG, '$-d' => $-d, # ractor-local (derived from created ractor): verbose '$VERBOSE' => $VERBOSE, '$-w' => $-w, '$-W' => $-W, '$-v' => $-v, # process-local (readonly): other commandline parameters '$-p' => $-p, '$-l' => $-l, '$-a' => $-a, # process-local (readonly): getpid '$$' => $$, # thread local: process result '$?' => $?, # scope local: match '$~' => $~.inspect, '$&' => $&, '$`' => $`, '$\'' => $', '$+' => $+, '$1' => $1, # scope local: last line '$_' => $_, # scope local: last backtrace '$@' => $@, '$!' => $!, # ractor local: stdin, out, err '$stdin' => $stdin.inspect, '$stdout' => $stdout.inspect, '$stderr' => $stderr.inspect, ``` Notes: Merged: https://github.com/ruby/ruby/pull/3670
2020-10-12change rb_ractor_queue to ring buffertompng
Notes: Merged: https://github.com/ruby/ruby/pull/3642
2020-10-10Add Ractor#receive and Ractor.receive and use it in all placesBenoit Daloze
* Keep Ractor#recv/Ractor.recv as an alias for now. Notes: Merged: https://github.com/ruby/ruby/pull/3626
2020-10-10remove debug codeKoichi Sasada
2020-09-25Frozen Struct can be shareable.Koichi Sasada
A frozen Struct object which refers to shareable objects should be shareable. Notes: Merged: https://github.com/ruby/ruby/pull/3580
2020-09-25Ractor.yield should raise if out-port is closedKoichi Sasada
Ractor.yield should raise Ractor::ClosedError if current Ractor's outgoing-port is closed. Notes: Merged: https://github.com/ruby/ruby/pull/3578
2020-09-25frozen T_OBJECT can be shareable.Koichi Sasada
If an T_OBJECT object is frozen and all ivars are shareable, the object should be shareable. Notes: Merged: https://github.com/ruby/ruby/pull/3575
2020-09-25Ractor#close_outgoping cancel Ractor.yieldKoichi Sasada
Ractor#close_outgoing should cancel waiting Ractor.yield. However, yield a value by the Ractor's block should not cancel (to recognize terminating Ractor, introduce rb_ractor_t::yield_atexit flag). Notes: Merged: https://github.com/ruby/ruby/pull/3572
2020-09-24add GC_GUARDKoichi Sasada
We observed mark miss on this point so we add RB_GC_GUARD() to avoid wrong free.
2020-09-20Validate name during initializationQuang-Minh Nguyen
Notes: Merged: https://github.com/ruby/ruby/pull/3555
2020-09-19strip trailing spaces [ci skip]Nobuyoshi Nakada
2020-09-18add debug log on enabling multi-ractor modeKoichi Sasada
Notes: Merged: https://github.com/ruby/ruby/pull/3548
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-06Fix typos [ci skip]Kazuhiro NISHIYAMA
2020-09-04Fixed heap-use-after-free on racterNobuyoshi Nakada
2020-09-04check multi_ractor mode at main_pKoichi Sasada
rb_ractor_main_p() need to access to the ractor pointer in TLS. However it is slow operation so that we need to skip this check if it is not multi-ractor mode (!ruby_multi_ractor). This performance regression is pointed at https://bugs.ruby-lang.org/issues/17100#note-27 Notes: Merged: https://github.com/ruby/ruby/pull/3513
2020-09-04Initialize loop variables of list_for_each for MS VCNobuyoshi Nakada
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