ruby-changes:62945
From: Koichi <ko1@a...>
Date: Tue, 15 Sep 2020 00:05:30 +0900 (JST)
Subject: [ruby-changes:62945] e81d7189a0 (master): sync fstring pool
https://git.ruby-lang.org/ruby.git/commit/?id=e81d7189a0 From e81d7189a09155344b3135903300dce450232402 Mon Sep 17 00:00:00 2001 From: Koichi Sasada <ko1@a...> Date: Fri, 11 Sep 2020 18:31:15 +0900 Subject: sync fstring pool fstring pool should be sync with other Ractors. diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb index 141962e..ab20082 100644 --- a/bootstraptest/test_ractor.rb +++ b/bootstraptest/test_ractor.rb @@ -521,4 +521,21 @@ assert_equal 'nil', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L521 r.name.inspect } +### +### Synchronization tests +### + +N = 100_000 + +# fstring pool +assert_equal "#{N}#{N}", %Q{ + N = #{N} + 2.times.map{ + Ractor.new{ + N.times{|i| -(i.to_s)} + } + }.map{|r| r.take}.join +} + end # if !ENV['GITHUB_WORKFLOW'] + diff --git a/common.mk b/common.mk index fef7c3d..c3fb948 100644 --- a/common.mk +++ b/common.mk @@ -13351,6 +13351,7 @@ string.$(OBJEXT): {$(VPATH)}internal/variable.h https://github.com/ruby/ruby/blob/trunk/common.mk#L13351 string.$(OBJEXT): {$(VPATH)}internal/warning_push.h string.$(OBJEXT): {$(VPATH)}internal/xmalloc.h string.$(OBJEXT): {$(VPATH)}missing.h +string.$(OBJEXT): {$(VPATH)}node.h string.$(OBJEXT): {$(VPATH)}onigmo.h string.$(OBJEXT): {$(VPATH)}oniguruma.h string.$(OBJEXT): {$(VPATH)}probes.dmyh @@ -13362,6 +13363,8 @@ string.$(OBJEXT): {$(VPATH)}st.h https://github.com/ruby/ruby/blob/trunk/common.mk#L13363 string.$(OBJEXT): {$(VPATH)}string.c string.$(OBJEXT): {$(VPATH)}subst.h string.$(OBJEXT): {$(VPATH)}util.h +string.$(OBJEXT): {$(VPATH)}vm_debug.h +string.$(OBJEXT): {$(VPATH)}vm_sync.h strlcat.$(OBJEXT): {$(VPATH)}config.h strlcat.$(OBJEXT): {$(VPATH)}internal/compiler_is.h strlcat.$(OBJEXT): {$(VPATH)}internal/compiler_is/apple.h diff --git a/string.c b/string.c index 0c4e76a..8de906b 100644 --- a/string.c +++ b/string.c @@ -53,6 +53,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L53 #include "ruby/re.h" #include "ruby/util.h" #include "ruby_assert.h" +#include "vm_sync.h" #define BEG(no) (regs->beg[(no)]) #define END(no) (regs->end[(no)]) @@ -364,13 +365,18 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L365 register_fstring(VALUE str) { VALUE ret; - st_table *frozen_strings = rb_vm_fstring_table(); - do { - ret = str; - st_update(frozen_strings, (st_data_t)str, - fstr_update_callback, (st_data_t)&ret); - } while (ret == Qundef); + RB_VM_LOCK_ENTER(); + { + st_table *frozen_strings = rb_vm_fstring_table(); + + do { + ret = str; + st_update(frozen_strings, (st_data_t)str, + fstr_update_callback, (st_data_t)&ret); + } while (ret == Qundef); + } + RB_VM_LOCK_LEAVE(); assert(OBJ_FROZEN(ret)); assert(!FL_TEST_RAW(ret, STR_FAKESTR)); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/