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 ¨Ââßãìáóóßáììïãáôåßéîóôáîãå¨ÖÁÌÕëìáóó© > { > ¨ÂÅ×ÏÂʨïâê¬ óôòõãô ÒÏâêåãô©> ¨ÂÂÊÓÅÔÕШïâê¬ ëìáóó¬ ÔßÏÂÊÅÃÔ©» > ¨Âåôõò¨ÖÁÌÕÅ©ïâê> } > > #define NEWOBJ(obj,type) type *obj = (type*)rb_newobj() > > VALUE > rb_newobj(void) > { > ¨Â¨äõòéîçßçã> ¨Âïîôßçã ±» > ¨Âõòéîçßçã °» > ¨Ââßâõ稢ïâêåãáììïãáôéïî äõòéîç çáòâáçãïììåãôéïî ðèáó墩» > ¨Â > > ¨Âåôõòòâßîå÷ïâêßæòïíßèåáð¨ïâêóðáãå©» > } > > static VALUE > rb_newobj_from_heap(rb_objspace_t *objspace) > { > ¨ÂÁÌÕÅ ïâê» > > ¨Â¨¨òõâùßçãßóôòåóó ¦¦ ¡òõâùßäéóáâìåßçãßóôòåóó© üü ¡æòååìéóô© > ¨Â¨¡èåáðóßéîãòåíåîô¨ïâêóðáã妦 ¡çáòâáçåßãïììåãô¨ïâêóðáãå©> ¨Âõòéîçßçã °» > ¨Ââßíåíåòòïò¨©> ¨Â > ¨Â > > ¨Ââê ¨ÖÁÌÕÅ©æòååìéóô» > ¨Âòååìéóæòååìéóô¾áó®æòåå®îåøô> > ¨ÂÅÍÚÅÒϨ¨öïé䪩ïâê¬ ÒÖÁÌÕű©> > ¨Âåôõòïâê» > } > > > > I doesnÃÕ 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 = Thread.new { > for a in 1..999 > bject.new > end > } > for b in 1..999 > bject.new > End > > Please tell me if some other mechanism solve the simultaneity issue. > Thanks Vince > > -- > Posted via http://www.ruby-forum.com/. >