mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
ractor: don't inherit the default thread group
[Bug #17506] `Thread.current.group` isn't shareable so it shouldn't be inherited by the main thread of a new Ractor. This cause an extra allocation when spawning a ractor, which could be elided with a bit of extra work, but not sure if it's worth the effort.
This commit is contained in:
parent
2263e26f40
commit
5e421ce8d9
Notes:
git
2025-03-31 08:26:10 +00:00
2 changed files with 28 additions and 3 deletions
20
thread.c
20
thread.c
|
@ -106,6 +106,7 @@
|
|||
#endif
|
||||
|
||||
static VALUE rb_cThreadShield;
|
||||
static VALUE cThGroup;
|
||||
|
||||
static VALUE sym_immediate;
|
||||
static VALUE sym_on_blocking;
|
||||
|
@ -795,6 +796,7 @@ struct thread_create_params {
|
|||
// for normal proc thread
|
||||
VALUE args;
|
||||
VALUE proc;
|
||||
VALUE group;
|
||||
|
||||
// for ractor
|
||||
rb_ractor_t *g;
|
||||
|
@ -853,7 +855,13 @@ thread_create_core(VALUE thval, struct thread_create_params *params)
|
|||
}
|
||||
|
||||
th->priority = current_th->priority;
|
||||
th->thgroup = current_th->thgroup;
|
||||
|
||||
if (params->group) {
|
||||
th->thgroup = params->group;
|
||||
}
|
||||
else {
|
||||
th->thgroup = current_th->thgroup;
|
||||
}
|
||||
|
||||
th->pending_interrupt_queue = rb_ary_hidden_new(0);
|
||||
th->pending_interrupt_queue_checked = 0;
|
||||
|
@ -993,13 +1001,20 @@ rb_thread_create(VALUE (*fn)(void *), void *arg)
|
|||
VALUE
|
||||
rb_thread_create_ractor(rb_ractor_t *r, VALUE args, VALUE proc)
|
||||
{
|
||||
VALUE thgroup = r->thgroup_default = rb_obj_alloc(cThGroup);
|
||||
#if RACTOR_CHECK_MODE > 0
|
||||
rb_ractor_setup_belonging_to(thgroup, r->pub.id);
|
||||
#endif
|
||||
|
||||
struct thread_create_params params = {
|
||||
.type = thread_invoke_type_ractor_proc,
|
||||
.g = r,
|
||||
.group = thgroup,
|
||||
.args = args,
|
||||
.proc = proc,
|
||||
};
|
||||
return thread_create_core(rb_thread_alloc(rb_cThread), ¶ms);
|
||||
RB_GC_GUARD(thgroup);
|
||||
return thread_create_core(rb_thread_alloc(rb_cThread), ¶ms);;
|
||||
}
|
||||
|
||||
|
||||
|
@ -5427,7 +5442,6 @@ Init_Thread_Mutex(void)
|
|||
void
|
||||
Init_Thread(void)
|
||||
{
|
||||
VALUE cThGroup;
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
|
||||
sym_never = ID2SYM(rb_intern_const("never"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue