From: Shri Borde Date: 2008-12-31T08:00:27+09:00 Subject: [ruby-core:20999] Supporting Thread.critical=with native threads --_000_710DF26F214D2B4BB94287123FFE980A2DD02CAA8DNAEXMSGC104re_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, Thread.critical=3D is supposed to not schedule any other thread, in additio= n to guaranteeing that only one thread is ever in the block with Thread.cri= tical=3D=3Dtrue. This is easier to support with green threads. With native threads, it is harder to do. I am working on IronRuby, and have= some questions: 1. Should it be by spec that other threads are not allowed to be scheduled?= Thread#inspect for the other threads actually says "run", not "sleep". 2. How would you test that the other threads are not scheduled. It can be d= one by having the other threads increment some class variable, and by check= ing that its value does not change. So this is mostly a rhetorical question= . 3. Given that implementations with native threads cannot support this perfe= ctly, how many apps would actually be affected? The few gems I have looked = at only need that Thread.critical=3Dtrue only behave like a critical sectio= n. The apps will work even if the other threads are scheduled, as long the = other threads block when they themselves try to set Thread.critical=3Dtrue.= According to http://www.megasolutions.net/ruby/basic-threading-question_ca= n-ruby-use-real-threads_-64225.aspx, JRuby supports this by having every th= read periodically do a checkpoint to see if it should suspend itself. It se= ems that most apps would continue working if there was only one checkpoint,= in Thread.critical=3D. Thanks, Shri --_000_710DF26F214D2B4BB94287123FFE980A2DD02CAA8DNAEXMSGC104re_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

Thread.critical=3D is supposed to not schedule any oth= er thread, in addition to guaranteeing that only one thread is ever in the blo= ck with Thread.critical=3D=3Dtrue. This is easier to support with green thread= s.

 

With native threads, it is harder to do. I am working = on IronRuby, and have some questions:

 

1. Should it be by spec that other threads are not all= owed to be scheduled? Thread#inspect for the other threads actually says “= run”, not “sleep”.

 

2. How would you test that the other threads are not scheduled. It can be done by having the other threads increment some class variable, and by checking that its value does not change. So this is mostly= a rhetorical question.

 

3. Given that implementations with native threads cann= ot support this perfectly, how many apps would actually be affected? The few g= ems I have looked at only need that Thread.critical=3Dtrue only behave like a cri= tical section. The apps will work even if the other threads are scheduled, as lon= g the other threads block when they themselves try to set Thread.critical=3Dt= rue. According to http://www.megasolutions.net/ruby/basic-thre= ading-question_can-ruby-use-real-threads_-64225.aspx, JRuby supports this by having every thread periodically do a checkpoint to = see if it should suspend itself. It seems that most apps would continue working= if there was only one checkpoint,in Thread.critical=3D.

 

Thanks,

Shri

 

--_000_710DF26F214D2B4BB94287123FFE980A2DD02CAA8DNAEXMSGC104re_--