From: Yukihiro Matsumoto Date: 2004-09-13T21:39:28+09:00 Subject: Re: [PATCH] dir.c --- Dir.chdir error handling Hi, In message "Re: [PATCH] dir.c --- Dir.chdir error handling" on Mon, 13 Sep 2004 16:54:06 +0900, H.Yamamoto writes: |But I'm still uncomfortable about volatile. ruby is large, I think we cannot |guarantee all VALUEs are guarded from compiler optimization. | |I think the safest way is to store object into volatile variable just after construction. | | volatile VALUE v = rb_str_new2("foo"); | | foo(v); /* don't have to think about GC */ | |but on this policy, we can't do this | | foo(rb_str_new2("foo")); | |.... totally. I'm not sure about your concern. If the string from rb_str_new() still used somewhere, it would not be treated as garbage. The only problem raises when you retrieve data from a VALUE, and forget about the original VALUE, e.g. VALUE s = rb_str_new2("foo"); char *ptr = RSTRING(s)->ptr; .. no reference to s, but ptr .. In the cases like this, you must protect your VALUE explicitly (by volatile), but not for rb_rescue() arguments etc. matz.