From: Paul Brannan Date: 2007-12-27T05:32:58+09:00 Subject: Re: [Spam] What does volatile assignment of *pos in rb_thread_s_new() do? On Sun, Dec 16, 2007 at 06:02:16AM +0900, Gonzalo Garramu?o wrote: > Brent Roman wrote: > > volatile VALUE *pos; > > > > pos = th->stk_pos; //<--- what does this accomplish? > > It keeps the value in the stack, preventing it from being GC'ed during > the run of that (and children) functions. > > The use of volatile is a hint to the compiler to not optimize away the > variable. Wouldn't the same thing be accomplished by marking the member in thread_mark instead? I see the same idiom being used in YARV, but I'm skeptical whether it is used correctly. IMO any time volatile is used without a comment is a bug. One example (vm.c): volatile int stored_safe = th->safe_level; It's unclear even from studying the code in detail why this variable is marked volatile. Paul