From: Yusuke Endoh Date: 2010-04-14T00:44:30+09:00 Subject: [ruby-dev:40977] [Bug #812] Failure: test_priority (TestThread) on mswin32 チケット #812 が更新されました。 (by Yusuke Endoh) 担当者 Koichi SasadaからYusuke Endohに変更 Target version 1.9.2にセット ruby -v -にセット 遠藤です。 2008年12月3日12:46 U.Nakamura : > 表題の通りですが、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 thr. 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 thr to integer. 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 ---------------------------------------- http://redmine.ruby-lang.org/issues/show/812 ---------------------------------------- http://redmine.ruby-lang.org