https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-06-26T13:30:02ZRuby Issue Tracking SystemRuby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=182422011-06-26T13:30:02Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>Project</strong> changed from <i>Ruby</i> to <i>Ruby master</i></li><li><strong>Category</strong> changed from <i>ext</i> to <i>ext</i></li></ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=228502011-12-17T10:00:59Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>ping? The subject of Queue performance came up again in:<br>
<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/391324" class="external">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/391324</a></p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=228512011-12-17T10:23:09Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones (Closed)" href="https://redmine.ruby-lang.org/issues/3620">#3620</a> has been updated by Eric Wong.</p>
<h2>ping? The subject of Queue performance came up again in:<br>
<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/391324" class="external">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/391324</a>
</h2>
<p>Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones (Closed)" href="https://redmine.ruby-lang.org/issues/3620">#3620</a>: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones<br>
<a href="http://redmine.ruby-lang.org/issues/3620" class="external">http://redmine.ruby-lang.org/issues/3620</a></p>
<p>Author: Ricardo Panaggio<br>
Status: Open<br>
Priority: Normal<br>
Assignee:<br>
Category: ext<br>
Target version:</p>
<p>=begin<br>
Queue, SizedQueue and ConditionVariable are important synchronization primitives and are nowadays implemented in Ruby.</p>
<p>Attached patch (initiated by myself and heavily enriched by Nobu) contains these sync primitives implemented in C, which makes them faster (see [1] for the benchmark's code):</p>
<p>Rehearsal -------------------------------------------------<br>
Q#push 1.590000 0.010000 1.600000 ( 1.605502)<br>
T#push 0.600000 0.010000 0.610000 ( 0.630444)<br>
Q#pop 4.390000 0.000000 4.390000 ( 4.389781)<br>
T#pop 0.580000 0.000000 0.580000 ( 0.578918)<br>
Q#empty? 0.480000 0.000000 0.480000 ( 0.484305)<br>
T#empty? 0.360000 0.000000 0.360000 ( 0.358559)<br>
Q#clear 1.210000 0.000000 1.210000 ( 1.214494)<br>
T#clear 0.600000 0.000000 0.600000 ( 0.588611)<br>
Q#size 0.370000 0.000000 0.370000 ( 0.365587)<br>
T#size 0.350000 0.000000 0.350000 ( 0.356985)<br>
Q#num_waiting 0.380000 0.000000 0.380000 ( 0.379199)<br>
T#num_waiting 0.370000 0.000000 0.370000 ( 0.368075)<br>
--------------------------------------- total: 11.300000sec</p>
<p>It has already been discussed on ruby-core (see ruby-core:31100).</p>
<p>This patch is one of the deliverables of my RubySoC project (slot <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: deadlock detection for 1.9 (Closed)" href="https://redmine.ruby-lang.org/issues/17">#17</a>): "Improving Ruby's Synchronization Primitives and Core Libraries" [2,3]</p>
<p>[1] <a href="http://github.com/panaggio/rubysoc-2010/blob/master/benchmarks/queue.rb" class="external">http://github.com/panaggio/rubysoc-2010/blob/master/benchmarks/queue.rb</a><br>
[2] <a href="http://pastebin.com/viSnfqe6" class="external">http://pastebin.com/viSnfqe6</a><br>
[3] <a href="http://rubysoc.org/projects" class="external">http://rubysoc.org/projects</a><br>
=end</p>
<p>--<br>
<a href="http://redmine.ruby-lang.org" class="external">http://redmine.ruby-lang.org</a></p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=247322012-03-18T17:52:31Znahi (Hiroshi Nakamura)nakahiro@gmail.com
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/24732/diff?detail_id=18038">diff</a>)</li><li><strong>Assignee</strong> set to <i>ko1 (Koichi Sasada)</i></li></ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=248712012-03-18T18:46:39Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=249272012-03-19T04:46:00Zfunny_falcon (Yura Sokolov)funny.falcon@gmail.com
<ul></ul><p>Related issue (but about plain ruby realization)<br>
<a href="https://bugs.ruby-lang.org/issues/6174" class="external">https://bugs.ruby-lang.org/issues/6174</a></p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=274292012-06-26T04:35:22Zko1 (Koichi Sasada)
<ul></ul><p>Sorry for absent from this request.</p>
<p>Eric, can this patch work fine on current trunk?<br>
... which patch should I use?</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=274612012-06-26T09:53:12Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>"ko1 (Koichi Sasada)" <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Eric, can this patch work fine on current trunk?<br>
... which patch should I use?</p>
</blockquote>
<p>Yes, I just tested final-queue.patch with current trunk (r36217)<br>
and it works.</p>
<p>The .gitignore hunk in the patch can be ignored, everything<br>
else creates a new file and doesn't conflict.</p>
<p>This is Richard's patch, btw. I'm not sure if Richard still<br>
pays attention to Ruby (haven't seen any activity from him in<br>
a while).</p>
<p>push/pop are still significantly faster on current trunk with the<br>
queue.rb benchmark:</p>
<pre><code> user system total real
</code></pre>
<p>Q#push 0.640000 0.000000 0.640000 ( 0.642801)<br>
T#push 0.200000 0.000000 0.200000 ( 0.197539)<br>
Q#pop 1.390000 0.000000 1.390000 ( 1.393139)<br>
T#pop 0.230000 0.000000 0.230000 ( 0.228802)</p>
<p>(<a href="https://raw.github.com/panaggio/rubysoc-2010/master/benchmarks/queue.rb" class="external">https://raw.github.com/panaggio/rubysoc-2010/master/benchmarks/queue.rb</a>)</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=274712012-06-26T16:18:44Zfunny_falcon (Yura Sokolov)funny.falcon@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/2816">final_queue_without_mutex.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2816/final_queue_without_mutex.diff">final_queue_without_mutex.diff</a> added</li></ul><p>It seems that there is no need for mutex in a native queue implementation (considering we have GVL),<br>
and so that queue_synchronized wrapper:<br>
rb_mutex_sleep could be replaces with rb_thread_sleep_forever without semantic change.</p>
<p>Without mutex, native queue becomes 2 times faster.<br>
Modified patch is attached.</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=275582012-06-29T17:53:24Zko1 (Koichi Sasada)
<ul></ul><p>Hi,</p>
<p>(2012/06/26 16:18), funny_falcon (Yura Sokolov) wrote:</p>
<blockquote>
<p>It seems that there is no need for mutex in a native queue implementation (considering we have GVL),<br>
and so that queue_synchronized wrapper:<br>
rb_mutex_sleep could be replaces with rb_thread_sleep_forever without semantic change.</p>
<p>Without mutex, native queue becomes 2 times faster.<br>
Modified patch is attached.</p>
</blockquote>
<p>I found a bug.</p>
<a name="begin-sample-code"></a>
<h3 >begin sample code<a href="#begin-sample-code" class="wiki-anchor">¶</a></h3>
<p>q = Thread::Queue.new<br>
#q = Queue.new<br>
th1 = Thread.new{<br>
begin<br>
p [:th1, q.pop]<br>
rescue RuntimeError => e<br>
sleep<br>
p e<br>
end<br>
}<br>
th2 = Thread.new{<br>
sleep 0.1<br>
p [:th2, q.pop]<br>
}<br>
p [th1, th2]<br>
sleep 0.5<br>
th1.raise "async interrupt!"<br>
sleep 0.5<br>
q << :s</p>
<a name="th1join"></a>
<h1 >th1.join<a href="#th1join" class="wiki-anchor">¶</a></h1>
<p>p [th1, th2]<br>
th2.join # BLOCK forever!</p>
<a name="end-sample-code"></a>
<h3 >end sample code<a href="#end-sample-code" class="wiki-anchor">¶</a></h3>
<p>When th1 escapes from blocking by "pop" by exception, then waiting list<br>
of Queue should be maintained (remove th1 from waiting list).</p>
<p>Other comment:</p>
<ul>
<li>
<p>"extthread" is good name?</p>
</li>
<li>
<p>variable name</p>
</li>
</ul>
<p>static void<br>
wakeup_all_threads(VALUE list)<br>
{<br>
VALUE thread, list0 = list;<br>
long i;</p>
<pre><code> list = rb_ary_subseq(list, 0, LONG_MAX);
rb_ary_clear(list0);
for (i = 0; i < RARRAY_LEN(list); ++i) {
thread = RARRAY_PTR(list)[i];
rb_thread_wakeup_alive(thread);
}
RB_GC_GUARD(list);
</code></pre>
<p>}</p>
<p>I prefer:</p>
<p>static void<br>
wakeup_all_threads(VALUE list0)<br>
{<br>
VALUE thread, list = rb_ary_subseq(list0, 0, LONG_MAX);<br>
long i;</p>
<pre><code> rb_ary_clear(list0);
for (i = 0; i < RARRAY_LEN(list); ++i) {
thread = RARRAY_PTR(list)[i];
rb_thread_wakeup_alive(thread);
}
RB_GC_GUARD(list);
</code></pre>
<p>}</p>
<p>But I prefer more:</p>
<p>static void<br>
wakeup_all_threads(VALUE list)<br>
{<br>
VALUE thread;<br>
long i;</p>
<pre><code> for (i = 0; i < RARRAY_LEN(list); ++i) {
thread = RARRAY_PTR(list)[i];
rb_thread_wakeup_alive(thread);
}
rb_ary_clear(list);
</code></pre>
<p>}</p>
<p>Any reason to dup array before iteration?</p>
<ul>
<li>T_DATA -> T_STRUCT or T_OBJECT</li>
</ul>
<p>In this case, you don't need to use T_DATA. You can only use T_STRUCT<br>
or T_OBJECT (with hidden attr). Maybe it will be simple.</p>
<p>Thanks,<br>
Koichi</p>
<blockquote>
<hr>
<p>Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones (Closed)" href="https://redmine.ruby-lang.org/issues/3620">#3620</a>: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones<br>
<a href="https://bugs.ruby-lang.org/issues/3620#change-27471" class="external">https://bugs.ruby-lang.org/issues/3620#change-27471</a></p>
</blockquote>
<p>--<br>
// SASADA Koichi at atdot dot net</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=296542012-09-22T09:00:11Zko1 (Koichi Sasada)
<ul></ul><p>ping.</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=319382012-10-30T08:39:42Zko1 (Koichi Sasada)
<ul><li><strong>Target version</strong> set to <i>2.6</i></li></ul><p>ping.<br>
I think it can be introduce into Ruby 2.0 if there is a nice implementation.</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=393732013-05-17T22:59:44ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/3709">patch.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3709/patch.diff">patch.diff</a> added</li></ul><p>I fixed some bugs:<br>
(1) blocking forever bug pointed out by ko1 in <a href="/issues/3620">[ruby-core:45950]</a><br>
(2) SEGV in do_sleep()<br>
(3) SizedQueue's bug which is similar to (1)</p>
<p>Now, the C implementation passes test-all.<br>
Following diff is from final_queue_without_mutex.diff to my patch.</p>
<p>diff --git a/ext/thread/thread.c b/ext/thread/thread.c<br>
index 9aff5e5..33365c1 100644<br>
--- a/ext/thread/thread.c<br>
+++ b/ext/thread/thread.c<br>
@@ -150,7 +150,7 @@ static VALUE<br>
do_sleep(VALUE args)<br>
{<br>
struct sleep_call *p = (struct sleep_call *)args;</p>
<ul>
<li>return rb_funcall(p->argv[0], rb_intern("sleep"), p->argc-1, p->argv+1);</li>
</ul>
<ul>
<li>return rb_funcall(p->argv[0], rb_intern("sleep"), p->argc-1, p->argv[1]); /* (2) */<br>
}</li>
</ul>
<p>static VALUE<br>
@@ -339,15 +339,31 @@ rb_queue_push(VALUE self, VALUE obj)<br>
return self;<br>
}</p>
<p>+struct waiting_delete {</p>
<ul>
<li>VALUE waiting;</li>
<li>VALUE th;<br>
+};</li>
<li>
</ul>
<p>+static VALUE<br>
+queue_delete_from_waiting(struct waiting_delete *p)<br>
+{</p>
<ul>
<li>rb_ary_delete(p->waiting, p->th);</li>
<li>return Qnil;<br>
+}</li>
<li>
</ul>
<p>static VALUE<br>
queue_do_pop(Queue *queue, VALUE should_block)<br>
{</p>
<ul>
<li>while (!RARRAY_LEN(queue->que)) {</li>
</ul>
<ul>
<li>struct waiting_delete args;</li>
<li>
<li>while (RARRAY_LEN(queue->que) == 0) {<br>
if (!(int)should_block) {<br>
rb_raise(rb_eThreadError, "queue empty");<br>
}</li>
</ul>
<ul>
<li>
<pre><code> rb_ary_push(queue->waiting, rb_thread_current());
</code></pre>
</li>
<li>
<pre><code> rb_thread_sleep_forever();
</code></pre>
</li>
</ul>
<ul>
<li>
<pre><code> args.waiting = queue->waiting;
</code></pre>
</li>
<li>
<pre><code> args.th = rb_thread_current();
</code></pre>
</li>
<li>
<pre><code> rb_ary_push(args.waiting, args.th);
</code></pre>
</li>
<li>
<pre><code> rb_ensure((VALUE (*)())rb_thread_sleep_forever, (VALUE)0, queue_delete_from_waiting, (VALUE)&args); /* (1) */
</code></pre>
<p>}</p>
<p>return rb_ary_shift(queue->que);<br>
@@ -590,9 +606,14 @@ rb_szqueue_max_set(VALUE self, VALUE vmax)<br>
static VALUE<br>
szqueue_do_push(SizedQueue *szqueue, VALUE obj)<br>
{</p>
</li>
<li>
<p>struct waiting_delete args;</p>
</li>
<li>
<p>VALUE thread;</p>
</li>
<li>
<p>while (queue_length(&szqueue->queue_) >= szqueue->max) {</p>
</li>
</ul>
<ul>
<li>
<pre><code> rb_ary_push(szqueue->queue_wait, rb_thread_current());
</code></pre>
</li>
<li>
<pre><code> rb_thread_sleep_forever();
</code></pre>
</li>
</ul>
<ul>
<li>
<pre><code> args.waiting = szqueue->queue_wait;
</code></pre>
</li>
<li>
<pre><code> args.th = rb_thread_current();
</code></pre>
</li>
<li>
<pre><code> rb_ary_push(args.waiting, args.th);
</code></pre>
</li>
<li>
<pre><code> rb_ensure((VALUE (*)())rb_thread_sleep_forever, (VALUE)0, queue_delete_from_waiting, (VALUE)&args); /* (3) */
</code></pre>
}<br>
return queue_do_push(&szqueue->queue_, obj);<br>
}</li>
</ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=393742013-05-17T23:19:32ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul></ul><p>Here is benchmark results.<br>
I used the code same as <a href="/issues/3620">[ruby-core:45871]</a>.<br>
( <a href="https://raw.github.com/panaggio/rubysoc-2010/master/benchmarks/queue.rb" class="external">https://raw.github.com/panaggio/rubysoc-2010/master/benchmarks/queue.rb</a> )</p>
<p>trunk (r40799):<br>
user system total real<br>
Q#push 3.290000 0.000000 3.290000 ( 3.292121)<br>
Q#pop 1.900000 0.000000 1.900000 ( 1.898899)<br>
Q#empty? 0.120000 0.000000 0.120000 ( 0.122000)<br>
Q#clear 1.700000 0.010000 1.710000 ( 1.706695)<br>
Q#size 0.130000 0.000000 0.130000 ( 0.128248)<br>
Q#num_waiting 0.120000 0.000000 0.120000 ( 0.117081)</p>
<p>proposed:<br>
user system total real<br>
T#push 0.130000 0.000000 0.130000 ( 0.138489)<br>
T#pop 0.120000 0.000000 0.120000 ( 0.119966)<br>
T#empty? 0.100000 0.000000 0.100000 ( 0.104266)<br>
T#clear 0.130000 0.000000 0.130000 ( 0.135279)<br>
T#size 0.110000 0.000000 0.110000 ( 0.104839)<br>
T#num_waiting 0.100000 0.000000 0.100000 ( 0.097017)</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=393852013-05-18T04:49:28Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
You can use (({rb_funcall2()})) instead here.</p>
<ul>
<li>return rb_funcall(p->argv[0], rb_intern("sleep"), p->argc-1, p->argv+1);</li>
</ul>
<ul>
<li>return rb_funcall(p->argv[0], rb_intern("sleep"), p->argc-1, p->argv[1]); /* (2) */<br>
=end</li>
</ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=394862013-05-22T21:07:11ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/3713">patch2.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3713/patch2.diff">patch2.diff</a> added</li></ul><p>2013/5/18 nobu (Nobuyoshi Nakada) <a href="mailto:nobu@ruby-lang.org" class="email">nobu@ruby-lang.org</a></p>
<blockquote>
<p>You can use rb_funcall2() instead here.</p>
</blockquote>
<p>I made a patch which use rb_funcall2().</p>
<p>diff from patch.diff to patch2.diff:</p>
<p>diff --git a/ext/thread/thread.c b/ext/thread/thread.c<br>
index 33365c1..f2d17e9 100644<br>
--- a/ext/thread/thread.c<br>
+++ b/ext/thread/thread.c<br>
@@ -142,15 +142,17 @@ rb_condvar_initialize(VALUE self)<br>
}</p>
<p>struct sleep_call {</p>
<ul>
<li>int argc;</li>
<li>VALUE *argv;</li>
</ul>
<ul>
<li>VALUE mutex;</li>
<li>VALUE timeout;<br>
};</li>
</ul>
<p>+static ID id_sleep;<br>
+<br>
static VALUE<br>
do_sleep(VALUE args)<br>
{<br>
struct sleep_call *p = (struct sleep_call *)args;</p>
<ul>
<li>return rb_funcall(p->argv[0], rb_intern("sleep"), p->argc-1, p->argv[1]);</li>
</ul>
<ul>
<li>return rb_funcall2(p->mutex, id_sleep, 1, &p->timeout);<br>
}</li>
</ul>
<p>static VALUE<br>
@@ -173,12 +175,16 @@ static VALUE<br>
rb_condvar_wait(int argc, VALUE *argv, VALUE self)<br>
{<br>
VALUE waiters = get_condvar_ptr(self)->waiters;</p>
<ul>
<li>VALUE mutex, timeout;<br>
struct sleep_call args;</li>
</ul>
<ul>
<li>args.argc = argc;</li>
<li>args.argv = argv;</li>
</ul>
<ul>
<li>rb_scan_args(argc, argv, "11", &mutex, &timeout);</li>
<li>
<li>args.mutex = mutex;</li>
<li>args.timeout = timeout;<br>
rb_ary_push(waiters, rb_thread_current());<br>
rb_ensure(do_sleep, (VALUE)&args, delete_current_thread, waiters);</li>
<li>return self;<br>
}</li>
</ul>
<p>@@ -607,7 +613,6 @@ static VALUE<br>
szqueue_do_push(SizedQueue *szqueue, VALUE obj)<br>
{<br>
struct waiting_delete args;</p>
<ul>
<li>
<p>VALUE thread;</p>
<p>while (queue_length(&szqueue->queue_) >= szqueue->max) {<br>
args.waiting = szqueue->queue_wait;<br>
@@ -699,6 +704,8 @@ Init_thread(void)<br>
VALUE rb_cQueue = DEFINE_CLASS_UNDER_THREAD(Queue, rb_cObject);<br>
VALUE rb_cSizedQueue = DEFINE_CLASS_UNDER_THREAD(SizedQueue, rb_cQueue);</p>
</li>
</ul>
<ul>
<li>id_sleep = rb_intern("sleep");</li>
<li>rb_define_alloc_func(rb_cConditionVariable, condvar_alloc);<br>
rb_define_method(rb_cConditionVariable, "initialize", rb_condvar_initialize, 0);<br>
rb_define_method(rb_cConditionVariable, "wait", rb_condvar_wait, -1);</li>
</ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=414082013-08-29T18:54:58Zko1 (Koichi Sasada)
<ul><li><strong>File</strong> <a href="/attachments/3918">thread.c</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3918/thread.c">thread.c</a> added</li></ul><p>I rewrite to use T_STRUCT instead of T_DATA (attached).</p>
<p>Matsushita-san:<br>
Could you check it?</p>
<p>Issue:<br>
With ext/thraed/thread.c instead of lib/thread.rb, we can't install ruby itself.</p>
<p>(1) rbinstall.rb is invoked with miniruby<br>
(2) rbinstall.rb requires rubygems.rb<br>
(3) rubygems.rb requires lib/rubygems/core_ext/kernel_require.rb<br>
(4) lib/rubygems/core_ext/kernel_require.rb requires lib/monitor.rb<br>
(5) lib/monitor.rb requires thread.rb<br>
Problems are<br>
(a) miniruby can't require extension libraries<br>
(b) rbinstall.rb is not invoked with -I option</p>
<p>Easy way to solve these problem is use rbinstall.rb by ./ruby instead of ./miniruby with -I option.</p>
<p>Another solution is to embed thread.rb features (CV and Queue) as embeded classes.</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=414172013-08-30T02:23:18Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>"ko1 (Koichi Sasada)" <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>Another solution is to embed thread.rb features (CV and Queue) as<br>
embeded classes.</p>
</blockquote>
<p>I prefer this with no extra .so. Too many .so files hurts load time.<br>
Just leave an empty thread.rb for compatibility.</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=414262013-08-30T14:53:40Zko1 (Koichi Sasada)
<ul></ul><p>(2013/08/30 12:14), SASADA Koichi wrote:</p>
<blockquote>
<p>A patch for this approach:<br>
<a href="http://www.atdot.net/sp/raw/m5xbsm" class="external">http://www.atdot.net/sp/raw/m5xbsm</a></p>
</blockquote>
<p>Note that last patch does not care about deadlock detection.</p>
<p>--<br>
// SASADA Koichi at atdot dot net</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=414272013-08-30T15:29:40Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>(13/08/29 18:54), ko1 (Koichi Sasada) wrote:</p>
<blockquote>
<p>Problems are<br>
(a) miniruby can't require extension libraries<br>
(b) rbinstall.rb is not invoked with -I option</p>
<p>Easy way to solve these problem is use rbinstall.rb by ./ruby instead of ./miniruby with -I option.</p>
</blockquote>
<p>Use $(RUNRUBY) in $(INSTRUBY) instead of $(MINIRUBY).</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=414282013-08-30T20:53:18Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>(13/08/30 15:26), Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>(13/08/29 18:54), ko1 (Koichi Sasada) wrote:</p>
<blockquote>
<p>Problems are<br>
(a) miniruby can't require extension libraries<br>
(b) rbinstall.rb is not invoked with -I option</p>
<p>Easy way to solve these problem is use rbinstall.rb by ./ruby instead of ./miniruby with -I option.</p>
</blockquote>
<p>Use $(RUNRUBY) in $(INSTRUBY) instead of $(MINIRUBY).</p>
</blockquote>
<p>Since tool/rbinstall.rb replaces $:, it doesn't work as-is.</p>
<p><br>
diff --git a/common.mk b/common.mk<br>
index f295fb5..64ff5cc 100644<br>
--- a/common.mk<br>
+++ b/common.mk<br>
@@ -123,7 +123,7 @@ SCRIPT_ARGS = --dest-dir="$(DESTDIR)" <br>
--make-flags="$(MAKEFLAGS)"<br>
EXTMK_ARGS = $(SCRIPT_ARGS) --extension $(EXTS) --extstatic $(EXTSTATIC) <br>
--make-flags="V=$(V) MINIRUBY='$(MINIRUBY)'" --<br>
-INSTRUBY = $(SUDO) $(MINIRUBY) $(srcdir)/tool/rbinstall.rb<br>
+INSTRUBY = $(SUDO) $(RUNRUBY) -r./$(arch)-fake $(srcdir)/tool/rbinstall.rb<br>
INSTRUBY_ARGS = $(SCRIPT_ARGS) <br>
--data-mode=$(INSTALL_DATA_MODE) <br>
--prog-mode=$(INSTALL_PROG_MODE) <br>
@@ -449,7 +449,7 @@ post-no-install-doc::</p>
<p>CLEAR_INSTALLED_LIST = clear-installed-list</p>
<p>-install-prereq: $(CLEAR_INSTALLED_LIST) PHONY<br>
+install-prereq: $(CLEAR_INSTALLED_LIST) yes-fake PHONY</p>
<p>clear-installed-list: PHONY<br>
@> $(INSTALLED_LIST) set MAKE="$(MAKE)"<br>
</p>
<p>--<br>
Nobu Nakada</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=416382013-09-05T20:52:37ZGlass_saga (Masaki Matsushita)glass.saga@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/3943">patch3.diff</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/3943/patch3.diff">patch3.diff</a> added</li></ul><p>Sorry for my late response.<br>
I fixed a bug in ext/thread.c (<a href="/issues/3620">[ruby-core:56861]</a>).<br>
It was not compatible with Objects extended by Mutex_m and test/test_mutex_m.rb failed.<br>
Moreover, I use rb_thread_sleep_deadly() to make it get along with deadlock detection.</p>
<p>Attached patch includes:</p>
<ul>
<li>updated ext/thread.c</li>
<li>added test from <a href="/issues/3620">[ruby-core:45950]</a> to test/thread/test_queue.rb</li>
<li>common.mk rewrited by Nakada-san</li>
</ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=416402013-09-05T21:59:13Zko1 (Koichi Sasada)
<ul></ul><p>(2013/09/05 20:52), Glass_saga (Masaki Matsushita) wrote:</p>
<blockquote>
<p>I fixed a bug in ext/thread.c (<a href="/issues/3620">[ruby-core:56861]</a>).<br>
It was not compatible with Objects extended by Mutex_m and test/test_mutex_m.rb failed.<br>
Moreover, I use rb_thread_sleep_deadly() to make it get along with deadlock detection.</p>
<p>Attached patch includes:</p>
<ul>
<li>updated ext/thread.c</li>
<li>added test from <a href="/issues/3620">[ruby-core:45950]</a> to test/thread/test_queue.rb</li>
<li>common.mk rewrited by Nakada-san</li>
</ul>
</blockquote>
<p>Go ahead.</p>
<p>I'll make another ticket to embed Queue in srcdir/thread.c.</p>
<p>--<br>
// SASADA Koichi at atdot dot net</p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=416502013-09-07T00:15:13ZAnonymous
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r42862.<br>
Ricardo, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>
<p>common.mk: use RUNRUBY instead of MINIRUBY because MINIRUBY can't<br>
require extension libraries. The patch is from nobu<br>
(Nobuyoshi Nakada).</p>
</li>
<li>
<p>ext/thread/extconf.rb: for build ext/thread/thread.c.</p>
</li>
<li>
<p>include/ruby/intern.h: ditto.</p>
</li>
<li>
<p>thread.c: ditto.</p>
</li>
<li>
<p>lib/thread.rb: removed and replaced by ext/thread/thread.c.</p>
</li>
<li>
<p>ext/thread/thread.c: Queue, SizedQueue and ConditionVariable<br>
implementations in C. This patch is based on patches from panaggio<br>
(Ricardo Panaggio) and funny_falcon (Yura Sokolov) and ko1<br>
(Koichi Sasada). <a href="/issues/3620">[ruby-core:31513]</a> [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones (Closed)" href="https://redmine.ruby-lang.org/issues/3620">#3620</a>]</p>
</li>
<li>
<p>test/thread/test_queue.rb (test_queue_thread_raise): add a test for<br>
ensuring that killed thread should be removed from waiting threads.<br>
It is based on a code by ko1 (Koichi Sasada). <a href="/issues/3620">[ruby-core:45950]</a></p>
</li>
</ul> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=417822013-09-13T03:23:24Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul></ul><p>(9/5/13 8:55 AM), SASADA Koichi wrote:</p>
<blockquote>
<p>(2013/09/05 20:52), Glass_saga (Masaki Matsushita) wrote:</p>
<blockquote>
<p>I fixed a bug in ext/thread.c (<a href="/issues/3620">[ruby-core:56861]</a>).<br>
It was not compatible with Objects extended by Mutex_m and test/test_mutex_m.rb failed.<br>
Moreover, I use rb_thread_sleep_deadly() to make it get along with deadlock detection.</p>
<p>Attached patch includes:</p>
<ul>
<li>updated ext/thread.c</li>
<li>added test from <a href="/issues/3620">[ruby-core:45950]</a> to test/thread/test_queue.rb</li>
<li>common.mk rewrited by Nakada-san</li>
</ul>
</blockquote>
<p>Go ahead.</p>
<p>I'll make another ticket to embed Queue in srcdir/thread.c.</p>
</blockquote>
<p>We already have.</p>
<p><a href="http://bugs.ruby-lang.org/issues/7923" class="external">http://bugs.ruby-lang.org/issues/7923</a></p> Ruby master - Feature #3620: Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby oneshttps://redmine.ruby-lang.org/issues/3620?journal_id=418742013-09-18T18:23:17Zko1 (Koichi Sasada)
<ul></ul><p>(2013/09/13 3:03), KOSAKI Motohiro wrote:</p>
<blockquote>
<p>We already have.</p>
<p><a href="http://bugs.ruby-lang.org/issues/7923" class="external">http://bugs.ruby-lang.org/issues/7923</a></p>
</blockquote>
<p>I feel "making trap safe Queue (Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Queue#push and Queue#pop makes trap safe (Closed)" href="https://redmine.ruby-lang.org/issues/7923">#7923</a>)" and embedding Queue<br>
class is not same.</p>
<p>--<br>
// SASADA Koichi at atdot dot net</p>