Bug #812
Failure: test_priority (TestThread) on mswin32
| Status: | Closed | Start date: | ||
|---|---|---|---|---|
| Priority: | Low | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | - | |||
| Target version: | 1.9.2 | |||
| ruby -v: | - |
Description
こんにちは、なかむら(う)です。 表題の通りですが、priorityの低いスレッドの選択率を下げる機構 はpthreadでもwin32でも同じなのに、win32だとまともに機能してい ないように見えるのはなぜでしょうか? 私の環境で実験した限りだと、だいたい30〜40%くらいの確率でこの テストは失敗になります。 微妙に効いているような、効いてなくてスレッド生成順序に依存し てるだけのような、微妙な感じですが... それでは。 -- U.Nakamura <usa@garbagecollect.jp>
History
Updated by ko1 (Koichi Sasada) over 3 years ago
- Assignee set to ko1 (Koichi Sasada)
Updated by mame (Yusuke Endoh) about 2 years ago
- Assignee changed from ko1 (Koichi Sasada) to mame (Yusuke Endoh)
- Target version set to 1.9.2
- ruby -v set to -
遠藤です。 2008年12月3日12:46 U.Nakamura <usa@garbagecollect.jp>: > 表題の通りですが、priorityの低いスレッドの選択率を下げる機構 > はpthreadでもwin32でも同じなのに、win32だとまともに機能してい > ないように見えるのはなぜでしょうか? この機構は、native_thread_yield() を呼んだときに極力他のスレッドに コンテキストスイッチしてくれないと働きません。 thread_win32.c では native_thread_yield() は Sleep(0) となっていて、 Sleep(0) は MSDN によると > 中断時間として 0ms を指定してこの関数を呼び出すと、現在のスレッドは > 自らに割り当てられているタイムスライスの残りの部分を放棄します。 らしいので、これが本当なら動きそうなものですが、どうなんでしょうね。 いずれにしても、このテストはプラットフォームとタイミングに強く依存 するのであまり適切でなかったかもしれません。すでになかださんによって コメントアウトされているので、解決していると思います。 Thread#priority, #priority= の rdoc は、高優先度のスレッドがいる限り 低優先度のスレッドが全く実行されないかのように読めるので、これを修正 しつつ、プラットフォームによっては無視されるということを書いて、この チケットはクローズします。 diff --git a/thread.c b/thread.c index 10d6047..40a3483 100644 --- a/thread.c +++ b/thread.c @@ -2142,8 +2142,11 @@ rb_thread_keys(VALUE self) * * Returns the priority of <i>thr</i>. Default is inherited from the * current thread which creating the new thread, or zero for the - * initial main thread; higher-priority threads will run before - * lower-priority threads. + * initial main thread; higher-priority thread will run more frequently + * than lower-priority threads (but lower-priority threads can also run). + * + * This is just hint for Ruby thread scheduler. It may be ignored on some + * platform. * * Thread.current.priority #=> 0 */ @@ -2162,7 +2165,11 @@ rb_thread_priority(VALUE thread) * thr.priority= integer => thr * * Sets the priority of <i>thr</i> to <i>integer</i>. Higher-priority threads - * will run before lower-priority threads. + * will run more frequently than lower-priority threads (but lower-priority + * threads can also run). + * + * This is just hint for Ruby thread scheduler. It may be ignored on some + * platform. * * count1 = count2 = 0 * a = Thread.new do -- Yusuke Endoh <mame@tsg.ne.jp>
Updated by usa (Usaku NAKAMURA) about 2 years ago
こんにちは、なかむら(う)です。 In message "[ruby-dev:40977] [Bug #812] Failure: test_priority (TestThread) on mswin32" on Apr.14,2010 00:44:30, <redmine@ruby-lang.org> wrote: > > 表題の通りですが、priorityの低いスレッドの選択率を下げる機構 > > はpthreadでもwin32でも同じなのに、win32だとまともに機能してい > > ないように見えるのはなぜでしょうか? > > この機構は、native_thread_yield() を呼んだときに極力他のスレッドに > コンテキストスイッチしてくれないと働きません。 > thread_win32.c では native_thread_yield() は Sleep(0) となっていて、 > Sleep(0) は MSDN によると > > > 中断時間として 0ms を指定してこの関数を呼び出すと、現在のスレッドは > > 自らに割り当てられているタイムスライスの残りの部分を放棄します。 > > らしいので、これが本当なら動きそうなものですが、どうなんでしょうね。 もちろん本当なので動きそうなのですが、なんでだろう、というの が未だに謎です。 > Thread#priority, #priority= の rdoc は、高優先度のスレッドがいる限り > 低優先度のスレッドが全く実行されないかのように読めるので、これを修正 > しつつ、プラットフォームによっては無視されるということを書いて、この > チケットはクローズします。 それでいいと思います。 それでは。 -- U.Nakamura <usa@garbagecollect.jp>
Updated by mame (Yusuke Endoh) about 2 years ago
- Status changed from Open to Closed