Hi Vince,

good point, but at the moment this is not an issue, thanks to the
Global Interpreter Lock: only one Ruby thread is ever executed at the
same time.  While this is not a great situation, it will at least make
sure that such a problem will never occur.
http://en.wikipedia.org/wiki/Global_Interpreter_Lock

Elise

On Tue, Apr 26, 2011 at 7:48 AM, dot c. <dot.cyclone / gmail.com> wrote:
> I'm studying Ruby 1.9.2 source code. Some issues about simultaneity.
>
> Object.new will call following funtion to allocate space from heap:
> static VALUE =A0rb_class_allocate_instance(VALUE klass)
> {
> =A0 =A0NEWOBJ(obj, struct RObject);
> =A0 =A0OBJSETUP(obj, klass, T_OBJECT);
> =A0 =A0return (VALUE)obj;
> }
>
> #define NEWOBJ(obj,type) type *obj =3D (type*)rb_newobj()
>
> VALUE
> rb_newobj(void)
> {
> =A0 =A0if (during_gc) {
> =A0dont_gc =3D 1;
> =A0during_gc =3D 0;
> =A0rb_bug("object allocation during garbage collection phase");
> =A0 =A0}
>
> =A0 =A0return rb_newobj_from_heap(objspace);
> }
>
> static VALUE
> rb_newobj_from_heap(rb_objspace_t *objspace)
> {
> =A0 =A0VALUE obj;
>
> =A0 =A0if ((ruby_gc_stress && !ruby_disable_gc_stress) || !freelist) {
> =A0if (!heaps_increment(objspace) && !garbage_collect(objspace)) {
> =A0 =A0 =A0during_gc =3D 0;
> =A0 =A0 =A0rb_memerror();
> =A0}
> =A0 =A0}
>
> =A0 =A0obj =3D (VALUE)freelist;
> =A0 =A0freelist =3D freelist->as.free.next;
>
> =A0 =A0MEMZERO((void*)obj, RVALUE, 1);
>
> =A0 =A0return obj;
> }
>
>
>
> I doesn=92t see any code(in rb_newobj_from_heap), which is to make sure
> only one thread can call the function rb_newobj at the same time in
> multi-threading.
> The issue found in many other places. It seems that there can be only
> one thread in Ruby. But class Thread can create another thread.
>
> x =3D Thread.new {
> for a in 1..999
> =A0Object.new
> end
> }
> for b in 1..999
> =A0Object.new
> End
>
> Please tell me if some other mechanism solve the simultaneity issue.
> Thanks Vince
>
> --
> Posted via http://www.ruby-forum.com/.
>