Skip to content

Commit

Permalink
free ractors with ractor_free
Browse files Browse the repository at this point in the history
Previously with RUBY_FREE_ON_EXIT, ractors where being xfree-ed which is incorrect since they are not xmalloced.
Instead we can free ractors with ractor free during shutdown. This change only effects main ractor freeing when RUBY_FREE_ON_EXIT is set.

Co-authored-by: John Hawthorn <john@hawthorn.email>
  • Loading branch information
2 people authored and peterzhu2118 committed Dec 15, 2023
1 parent 049a9bd commit 474b4c4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 5 deletions.
2 changes: 1 addition & 1 deletion gc.c
Expand Up @@ -4607,7 +4607,7 @@ rb_objspace_free_objects(rb_objspace_t *objspace)
VALUE vp = (VALUE)p;
switch (BUILTIN_TYPE(vp)) {
case T_DATA: {
if (rb_obj_is_mutex(vp) || rb_obj_is_thread(vp)) {
if (rb_obj_is_mutex(vp) || rb_obj_is_thread(vp) || rb_obj_is_main_ractor(vp)) {
obj_free(objspace, vp);
}
break;
Expand Down
4 changes: 0 additions & 4 deletions vm.c
Expand Up @@ -3006,9 +3006,6 @@ ruby_vm_destruct(rb_vm_t *vm)
rb_free_warning();
rb_free_rb_global_tbl();
rb_free_loaded_features_index(vm);
rb_ractor_t *r = vm->ractor.main_ractor;
xfree(r->sync.recv_queue.baskets);
xfree(r->sync.takers_queue.baskets);

rb_id_table_free(vm->negative_cme_table);
st_free_table(vm->overloaded_cme_table);
Expand Down Expand Up @@ -3060,7 +3057,6 @@ ruby_vm_destruct(rb_vm_t *vm)
rb_objspace_free_objects(objspace);
rb_free_generic_iv_tbl_();
if (th) {
xfree(th->ractor);
xfree(stack);
ruby_mimfree(th);
}
Expand Down

0 comments on commit 474b4c4

Please sign in to comment.