followup 0bdb38ba6be208064a514c12a9b80328645689f8
(forgot to amend...)
This commit is contained in:
parent
1d3091b4db
commit
e09c23433e
Notes:
git
2024-12-13 08:06:16 +00:00
4
NEWS.md
4
NEWS.md
@ -83,6 +83,9 @@ Note: We're only listing outstanding class updates.
|
||||
* Ractor.[] and Ractor.[]= are added to access the ractor local storage
|
||||
of the current Ractor. [[Feature #20715]]
|
||||
|
||||
* `Ractor.store_if_absent(key){ init }` is added to initialize ractor local
|
||||
variables in thread-safty. [[Feature #20875]]
|
||||
|
||||
* Range
|
||||
|
||||
* Range#size now raises TypeError if the range is not iterable. [[Misc #18984]]
|
||||
@ -401,6 +404,7 @@ details of the default gems or bundled gems.
|
||||
[Bug #20795]: https://bugs.ruby-lang.org/issues/20795
|
||||
[Feature #20811]: https://bugs.ruby-lang.org/issues/20811
|
||||
[Feature #20860]: https://bugs.ruby-lang.org/issues/20860
|
||||
[Feature #20875]: https://bugs.ruby-lang.org/issues/20875
|
||||
[Feature #20876]: https://bugs.ruby-lang.org/issues/20876
|
||||
[Feature #20884]: https://bugs.ruby-lang.org/issues/20884
|
||||
[Feature #20902]: https://bugs.ruby-lang.org/issues/20902
|
||||
|
2
ractor.c
2
ractor.c
@ -3677,6 +3677,8 @@ ractor_local_storage_mark(rb_ractor_t *r)
|
||||
if (r->idkey_local_storage) {
|
||||
rb_id_table_foreach_values(r->idkey_local_storage, idkey_local_storage_mark_i, NULL);
|
||||
}
|
||||
|
||||
rb_gc_mark(r->local_storage_store_lock);
|
||||
}
|
||||
|
||||
static int
|
||||
|
14
ractor.rb
14
ractor.rb
@ -856,6 +856,20 @@ class Ractor
|
||||
Primitive.ractor_local_value_set(sym, val)
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# Ractor.store_if_absent(key){ init_block }
|
||||
#
|
||||
# If the correponding value is not set, yield a value with
|
||||
# init_block and store the value in thread-safe manner.
|
||||
# This method returns corresponding stored value.
|
||||
#
|
||||
# (1..10).map{
|
||||
# Thread.new(it){|i|
|
||||
# Ractor.store_if_absent(:s){ f(); i }
|
||||
# #=> return stored value of key :s
|
||||
# }
|
||||
# }.map(&:value).uniq.size #=> 1 and f() is called only once
|
||||
#
|
||||
def self.store_if_absent(sym)
|
||||
Primitive.ractor_local_value_store_if_absent(sym)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user