-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

nobu / ruby-lang.org wrote:
> Ruby GC scans the current machine stack to detect live objects,
> from the bottom of it through the current top of it.  Note that
> the bottom is initialized the position of the stack when
> ruby_init() is called.  If you run it from another native
> thread other than the initial thread, the stack pointer will
> point another stack, and GC will run out "gaps" between those
> stacks.

Ah! Now I see. Thank you. :-)


>> That's my understanding of the error message. If I am correct, then
>> a solution to this problem would be to prohibit the C program from
>> using Ruby's C API functions. That way, the C program never creates
>> any Ruby objects which can be garbage collected by the embedded Ruby
>> interpreter that runs inside another thread.
> 
> Incorrect.
> 
> You have to ensure rb_gc() will run only in the initial thread,
> and all objects created in your program will be refered from
> somewhere other than the main stack.

Could you suggest a way to do this?

I hoped that after ruby_init() was called, all new Ruby objects
would automatically use the stack pointer prepared by ruby_init().
Unfortunately, that was not so:

I tried the following scenario where the C process (1) creates and
runs the Ruby pthread, and (2) creates a Ruby array. But when the C
process creates the Ruby array, the cross-thread violation occurs.
Meaning that new Ruby objects are always created with respect to the
stack pointer of the current thread/process, not with respect to the
stack pointer prepared by ruby_init().


{process:
	pthread_create();
	...

	{pthread:
		ruby_init();
		...
		ruby_run();
	}

	...
	rb_ary_new();  // causes cross-thread violation on rb_gc()
}


At present, the only solution I know is to prohibit the C process
from creating Ruby objects. Is there a way that the C process can
create and use Ruby objects with respect to the stack pointer
prepared by ruby_init()?

Thanks.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEQqvfmV9O7RYnKMcRAgTmAKCCLo1MU8T15FEgWcH0XYb4NLu3rQCdHJSa
EpZ1vrFIGmmmFnjzX69zIeg=
=+x2Y
-----END PGP SIGNATURE-----