https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112009-07-14T00:14:10ZRuby Issue Tracking SystemRuby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=46752009-07-14T00:14:10Zyugui (Yuki Sonoda)yugui@yugui.jp
<ul><li><strong>Priority</strong> changed from <i>Normal</i> to <i>3</i></li><li><strong>Target version</strong> changed from <i>1.9.1</i> to <i>2.0.0</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=68072009-11-13T01:00:17Zdocwhat (Christian Höltje)docwhat@gmail.com
<ul></ul><h2>=begin<br>
This also happens when running "make test" in solaris but not "env RUBYLIB=./lib ./ruby test/ruby/test_thread.rb"</h2>
<p>test_thread.rb ....bootstraptest.tmp.rb:6: [BUG] pthread_cond_timedwait: 22<br>
ruby 1.9.1p243 (2009-07-16 revision 24175) [sparc-solaris2.8]</p>
<h2>-- control frame ----------<br>
c:0010 p:---- s:0028 b:0028 l:000027 d:000027 CFUNC :join<br>
c:0009 p:0013 s:0024 b:0024 l:0018b8 d:000023 BLOCK bootstraptest.tmp.rb:6<br>
c:0008 p:---- s:0020 b:0020 l:000019 d:000019 FINISH<br>
c:0007 p:---- s:0018 b:0018 l:000017 d:000017 CFUNC :each<br>
c:0006 p:0018 s:0015 b:0015 l:0018b8 d:002430 BLOCK bootstraptest.tmp.rb:3<br>
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH<br>
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :times<br>
c:0003 p:0013 s:0007 b:0006 l:0018b8 d:001fd8 EVAL bootstraptest.tmp.rb:2<br>
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH<br>
c:0001 p:0000 s:0002 b:0002 l:0018b8 d:0018b8 TOP</h2>
<p>-- Ruby level backtrace information-----------------------------------------<br>
bootstraptest.tmp.rb:6:in <code>join' bootstraptest.tmp.rb:6:in </code>block (2 levels) in '<br>
bootstraptest.tmp.rb:3:in <code>each' bootstraptest.tmp.rb:3:in </code>block in '<br>
bootstraptest.tmp.rb:2:in <code>times' bootstraptest.tmp.rb:2:in </code>'</p>
<p>[NOTE]<br>
You may encounter a bug of Ruby interpreter. Bug reports are welcome.<br>
For details: <a href="http://www.ruby-lang.org/bugreport.html" class="external">http://www.ruby-lang.org/bugreport.html</a></p>
<p>E......</p>
<p>It then hangs at this test.<br>
=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=104182010-04-22T02:31:29Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Assignee</strong> set to <i>mame (Yusuke Endoh)</i></li></ul><p>=begin<br>
Hi,</p>
<p>I guess this is the limitation of Solaris:</p>
<ul>
<li>
<p><a href="http://bugs.opensolaris.org/view_bug.do?bug_id=4038480" class="external">http://bugs.opensolaris.org/view_bug.do?bug_id=4038480</a></p>
</li>
<li>
<p><a href="http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view" class="external">http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view</a></p>
<p>EINVAL<br>
...<br>
For cond_timedwait(), the specified number of seconds, abstime,<br>
is greater than current_time + 100,000,000, where current_time<br>
is the current time, or the number of nanoseconds is greater<br>
than or equal to 1,000,000,000.</p>
</li>
</ul>
<p>Maybe, HP-UX has the same limitation, though I cannot find the<br>
evidence.</p>
<p>I wrote a workaround patch:</p>
<p>diff --git a/thread_pthread.c b/thread_pthread.c<br>
index e6295db..7387724 100644<br>
--- a/thread_pthread.c<br>
+++ b/thread_pthread.c<br>
@@ -633,6 +633,35 @@ native_sleep(rb_thread_t *th, struct timeval *tv)<br>
(unsigned long)ts.tv_sec, ts.tv_nsec);<br>
r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,<br>
&th->interrupt_lock, &ts);</p>
<ul>
<li>
<pre><code> if (r == EINVAL) {
</code></pre>
</li>
<li>
<pre><code> /* workaround for Solaris: wait by MEGA_SEC's.
</code></pre>
</li>
<li>
<pre><code> * on Solaris, pthread_cond_timedwait fails with EINVAL
</code></pre>
</li>
<li>
<pre><code> * if time is too far from now. [Bug #1341]
</code></pre>
</li>
<li>
<pre><code> * - http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view
</code></pre>
</li>
<li>
<pre><code> * - http://bugs.opensolaris.org/view_bug.do?bug_id=4038480
</code></pre>
</li>
<li>
<pre><code> */
</code></pre>
</li>
</ul>
<p>+#define MEGA_SEC 1000000</p>
<ul>
<li>
<pre><code> struct timeval ltv = *tv;
</code></pre>
</li>
<li>
<pre><code> r = ETIMEDOUT;
</code></pre>
</li>
<li>
<pre><code> while (r == ETIMEDOUT && ltv.tv_sec > MEGA_SEC) {
</code></pre>
</li>
<li>
<pre><code> ts.tv_sec = tvn.tv_sec + MEGA_SEC;
</code></pre>
</li>
<li>
<pre><code> ts.tv_nsec = tvn.tv_usec * 1000;
</code></pre>
</li>
<li>
<pre><code> ltv.tv_sec -= MEGA_SEC;
</code></pre>
</li>
<li>
<pre><code> r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,
</code></pre>
</li>
<li>
<pre><code> &th->interrupt_lock, &ts);
</code></pre>
</li>
<li>
<pre><code> if (r && r != ETIMEDOUT) rb_bug_errno("pthread_cond_timedwait", r);
</code></pre>
</li>
<li>
<pre><code> }
</code></pre>
</li>
<li>
<pre><code> if (r == ETIMEDOUT) {
</code></pre>
</li>
<li>
<pre><code> ts.tv_sec = tvn.tv_sec + ltv.tv_sec;
</code></pre>
</li>
<li>
<pre><code> ts.tv_nsec = (tvn.tv_usec + ltv.tv_usec) * 1000;
</code></pre>
</li>
<li>
<pre><code> if (ts.tv_nsec >= PER_NANO){
</code></pre>
</li>
<li>
<pre><code> ts.tv_sec += 1;
</code></pre>
</li>
<li>
<pre><code> ts.tv_nsec -= PER_NANO;
</code></pre>
</li>
<li>
<pre><code> }
</code></pre>
</li>
<li>
<pre><code> r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,
</code></pre>
</li>
<li>
<pre><code> &th->interrupt_lock, &ts);
</code></pre>
</li>
<li>
<pre><code> }
</code></pre>
</li>
<li>
<pre><code> }
if (r && r != ETIMEDOUT) rb_bug_errno("pthread_cond_timedwait", r);
thread_debug("native_sleep: pthread_cond_timedwait end (%d)\n", r);
</code></pre>
</li>
</ul>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=108132010-05-06T06:01:22Zgraza (Graham Agnew)graham.agnew@gmail.com
<ul></ul><p>=begin<br>
Today I downloaded, patched, and compiled the latest snapshot.</p>
<p>On HP-UX, that patch stopped the rb_bug_errno happening, although test/ruby/test_thread.rb scripts blocked indefinitely. On being interrupted it was the following test:</p>
<p><a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: cannot make with bison-2.4.1 (Closed)" href="https://redmine.ruby-lang.org/issues/874">#874</a> test_thread.rb:34:in `<top (required)>':</p>
<p>The code in your patch doesn't look right to me. Shouldn't the code re-fetch the time using gettimeofday each time through the loop, and then add the MEGA_SEC to that? As it is, it's wrong because it adds a MEGA_SEC to tvn, so after one MEGA_SEC it will enter a hard loop.</p>
<p>Cheers,<br>
Gra.<br>
=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=108152010-05-06T09:23:46Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>2010/5/6 Graham Agnew <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>On HP-UX, that patch stopped the rb_bug_errno happening, although the test/ruby/test_io.rb and test/ruby/test_thread.rb scripts both blocked indefinitely.</p>
<p>The code in your patch doesn't look right to me. ?Shouldn't the code re-fetch the time using gettimeofday each time through the loop, and then add the MEGA_SEC to that? ?As it is, it's wrong because it adds a MEGA_SEC to tvn, so after one MEGA_SEC it will enter a hard loop.</p>
</blockquote>
<p>Thank you for your testing! How about the following patch?</p>
<p>To tell the truth, I'm writing a patch without test because I<br>
don't have HP-UX. If this is wrong again, It is really helpful<br>
for you to correct the patch by yourself.</p>
<p>diff --git a/thread_pthread.c b/thread_pthread.c<br>
index e6295db..3c13f72 100644<br>
--- a/thread_pthread.c<br>
+++ b/thread_pthread.c<br>
@@ -631,8 +631,29 @@ native_sleep(rb_thread_t *th, struct timeval *tv)<br>
int r;<br>
thread_debug("native_sleep: pthread_cond_timedwait start (%ld, %ld)\n",<br>
(unsigned long)ts.tv_sec, ts.tv_nsec);</p>
<ul>
<li>
<pre><code> again:
r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,
&th->interrupt_lock, &ts);
</code></pre>
</li>
<li>
<pre><code> if (r == EINVAL) {
</code></pre>
</li>
<li>
<pre><code> /* workaround for Solaris: wait by MEGA_SEC's.
</code></pre>
</li>
<li>
<pre><code> * on Solaris, pthread_cond_timedwait fails with EINVAL
</code></pre>
</li>
<li>
<pre><code> * if time is too far from now. [Bug #1341]
</code></pre>
</li>
<li>
<pre><code> * - http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view
</code></pre>
</li>
<li>
<pre><code> * - http://bugs.opensolaris.org/view_bug.do?bug_id=4038480
</code></pre>
</li>
<li>
<pre><code> */
</code></pre>
</li>
</ul>
<p>+#define MEGA_SEC 1000000</p>
<ul>
<li>
<pre><code> struct timespec lts;
</code></pre>
</li>
<li>
<pre><code> r = ETIMEDOUT;
</code></pre>
</li>
<li>
<pre><code> while (r == ETIMEDOUT) {
</code></pre>
</li>
<li>
<pre><code> gettimeofday(&tvn, NULL);
</code></pre>
</li>
<li>
<pre><code> lts.tv_sec = tvn.tv_sec + MEGA_SEC;
</code></pre>
</li>
<li>
<pre><code> lts.tv_nsec = tvn.tv_usec * 1000;
</code></pre>
</li>
<li>
<pre><code> if (lts.tv_sec >= ts.tv_sec) goto again;
</code></pre>
</li>
<li>
<pre><code> r = pthread_cond_timedwait(&th->native_thread_data.sleep_cond,
</code></pre>
</li>
<li>
<pre><code> &th->interrupt_lock, &lts);
</code></pre>
</li>
<li>
<pre><code> if (r && r != ETIMEDOUT) rb_bug_errno("pthread_cond_timedwait", r);
</code></pre>
</li>
<li>
<pre><code> }
</code></pre>
</li>
<li>
<pre><code> }
if (r && r != ETIMEDOUT) rb_bug_errno("pthread_cond_timedwait", r);
thread_debug("native_sleep: pthread_cond_timedwait end (%d)\n", r);
</code></pre>
</li>
</ul>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p>
<p>=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=108622010-05-08T01:19:08Zgraza (Graham Agnew)graham.agnew@gmail.com
<ul></ul><p>=begin<br>
Hi Yusuke,</p>
<p>That code looks better although I'm still getting test/ruby/test_thread.rb blocking indefinitely. I will see if I can attach to the process with a debugger and figure out what it's blocked on.</p>
<p>Thanks,<br>
Gra.<br>
=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=133722010-09-14T16:35:36Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li></ul><p>=begin</p>
<p>=end</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=177022011-06-11T14:25:31Zko1 (Koichi Sasada)
<ul></ul><p>Endo-san,</p>
<p>Can we close this issue?</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=177602011-06-11T16:28:04Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>I guess it still reproduces on Solaris.<br>
I have no idea about HP-UX.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=177892011-06-11T17:22:59Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul></ul><p>Now, following two links are dead. Do anyone know new URLs?</p>
<ul>
<li>
<ul>
<li><a href="http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view" class="external">http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view</a></li>
</ul>
</li>
<li>
<ul>
<li><a href="http://bugs.opensolaris.org/view_bug.do?bug_id=4038480" class="external">http://bugs.opensolaris.org/view_bug.do?bug_id=4038480</a></li>
</ul>
</li>
</ul> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=188172011-07-05T01:35:46Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Open</i></li><li><strong>Assignee</strong> deleted (<del><i>mame (Yusuke Endoh)</i></del>)</li></ul><p>Hello,</p>
<blockquote>
<p>Now, following two links are dead. Do anyone know new URLs?</p>
<ul>
<li>
<ul>
<li><a href="http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view" class="external">http://docs.sun.com/app/docs/doc/806-0630/6j9vkb8ct?a=view</a></li>
</ul>
</li>
<li>
<ul>
<li><a href="http://bugs.opensolaris.org/view_bug.do?bug_id=4038480" class="external">http://bugs.opensolaris.org/view_bug.do?bug_id=4038480</a></li>
</ul>
</li>
</ul>
</blockquote>
<p>Here.</p>
<p><a href="http://download.oracle.com/docs/cd/E19683-01/816-0216/6m6ngupgv/index.html" class="external">http://download.oracle.com/docs/cd/E19683-01/816-0216/6m6ngupgv/index.html</a></p>
<p>EINVAL<br>
Invalid argument. For cond_init(), type is not a recognized type. For cond_timedwait(), the specified number of seconds, abstime, is greater than current_time + 100,000,000, where current_time is the current time, or the number of nanoseconds is greater than or equal to 1,000,000,000.</p>
<p>The problem that I now focus on is that pthread_cond_timedwait may fail<br>
with EINVAL if an argument is greater than current_time + 100,000,000<br>
on Solaris.<br>
The patch of <a href="https://blade.ruby-lang.org/ruby-core/29702">[ruby-core:29702]</a> is too old and cannot be applied, so<br>
I rewrote and committed a new patch at r32409. Now, "make test" passes<br>
on Solaris. Congrats.</p>
<p>Unfortunately, the original issue that OP reported was a different problem.<br>
But I guess that there is no hope of fixing the issue. At least I cannot.<br>
So I resign the assignee of this ticket. Sorry for late action.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=196652011-07-25T20:19:03Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>Feedback about HP-UX is welcome</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=201572011-08-08T21:10:15Zkosaki (Motohiro KOSAKI)kosaki.motohiro@gmail.com
<ul><li><strong>Subject</strong> changed from <i>pthread_cond_timedwait failing in 1.9.1-p0 thread tests</i> to <i>pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2</i></li></ul> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=319672012-10-30T09:31:23Zko1 (Koichi Sasada)
<ul><li><strong>Target version</strong> changed from <i>2.0.0</i> to <i>2.6</i></li></ul><p>Please tell us if you have HP-UX.</p> Ruby master - Bug #1341: pthread_cond_timedwait failing in 1.9.1-p0 thread tests on HP-UX 11i v2https://redmine.ruby-lang.org/issues/1341?journal_id=324242012-11-05T22:56:15Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Rejected</i></li></ul><p>HP-UX is not supported. I'm sorry, but please create a patch that works yourself.<br>
If you provide us the patch and it looks benign to other platforms, we may apply it to trunk.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p>