ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:100816] [Ruby master Feature#17323] Ractor::LVar to provide ractor-local storage
@ 2020-11-12 16:55 ko1
  2020-11-12 17:07 ` [ruby-core:100817] " ko1
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: ko1 @ 2020-11-12 16:55 UTC (permalink / raw)
  To: ruby-core

Issue #17323 has been reported by ko1 (Koichi Sasada).

----------------------------------------
Feature #17323: Ractor::LVar to provide ractor-local storage
https://bugs.ruby-lang.org/issues/17323

* Author: ko1 (Koichi Sasada)
* Status: Open
* Priority: Normal
----------------------------------------
Ruby supports thread and fiber local storage:

* `Thread#[sym]` provides *Fiber* local storage
* `Thread#thread_variable_get(sym)

These APIs can access other threads/fibers like that:

```ruby
th = Thread.new{
  Thread.current.thread_variable_set(:a, 10)
}
th.join
# access from main thread to child thread
p th.thread_variable_get(:a)
```

To make Ractor local storage, this kind of feature should not be allowed to protect isolation.

This ticket propose alternative API `Ractor::LVar` that allows to provide Ractor local variable.

```ruby
LV1 = Ractor::LVar.new

p LV1.value #=> nil # default value
LV1.value = 'hello' # can set unshareable objects because LVar is ractor local.

Ractor.new do
  LV1.value = 'world' # set Ractor local variable
end.take

p LV1.value #=> 'hello'


# Lvar.new can accept default_proc which should be isolated Proc.

LV2 = Ractor::LVar.new{ "x" * 4 }
p LV2.value #=> "xxxx"
LV2.value = 'yyy'

Ractor.new do
  p LV2.value #=> 'xxx'
end

p LV2.value #=> 'yyy'
```

This API doesn't support accessing from other ractors.

`Ractor::LVar` is from `Ractor::TVar`, but I have no strong opinion about it.
For example, `Ractor::LocalVariable` is longer and clearer.

Implementation: https://github.com/ruby/ruby/pull/3762




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2021-01-07 13:11 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 16:55 [ruby-core:100816] [Ruby master Feature#17323] Ractor::LVar to provide ractor-local storage ko1
2020-11-12 17:07 ` [ruby-core:100817] " ko1
2020-11-12 18:24 ` [ruby-core:100818] " marcandre-ruby-core
2020-11-12 18:44 ` [ruby-core:100819] " ko1
2020-11-13 19:53 ` [ruby-core:100842] " daniel
2020-11-16  7:59 ` [ruby-core:100868] " ko1
2020-12-06 23:20 ` [ruby-core:101271] " marcandre-ruby-core
2020-12-07  4:26 ` [ruby-core:101275] " marcandre-ruby-core
2020-12-10  7:06 ` [ruby-core:101363] " matz
2020-12-10 10:50 ` [ruby-core:101379] " marcandre-ruby-core
2020-12-10 11:43 ` [ruby-core:101382] " eregontp
2020-12-10 12:20 ` [ruby-core:101388] " marcandre-ruby-core
2020-12-21 20:58 ` [ruby-core:101607] " ko1
2021-01-06 15:09 ` [ruby-core:101959] " dsisnero
2021-01-06 15:11 ` [ruby-core:101960] " chris
2021-01-06 16:22 ` [ruby-core:101964] " dsisnero
2021-01-06 16:25 ` [ruby-core:101965] " chris
2021-01-07  6:33 ` [ruby-core:101970] " ko1
2021-01-07 13:11 ` [ruby-core:101971] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).