Project

General

Profile

Actions

Bug #812

closed

Failure: test_priority (TestThread) on mswin32

Added by usa (Usaku NAKAMURA) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
-
Backport:
[ruby-dev:37252]

Description

=begin
こんにちは、なかむら(う)です。

表題の通りですが、priorityの低いスレッドの選択率を下げる機構
はpthreadでもwin32でも同じなのに、win32だとまともに機能してい
ないように見えるのはなぜでしょうか?

私の環境で実験した限りだと、だいたい30〜40%くらいの確率でこの
テストは失敗になります。
微妙に効いているような、効いてなくてスレッド生成順序に依存し
てるだけのような、微妙な感じですが...

それでは。

U.Nakamura
=end

Actions #1

Updated by ko1 (Koichi Sasada) over 15 years ago

  • Assignee set to ko1 (Koichi Sasada)

=begin

=end

Actions #2

Updated by mame (Yusuke Endoh) almost 14 years ago

  • Assignee changed from ko1 (Koichi Sasada) to mame (Yusuke Endoh)
  • Target version set to 1.9.2
  • ruby -v set to -

=begin
遠藤です。

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
=end

Actions #3

Updated by usa (Usaku NAKAMURA) almost 14 years ago

=begin
こんにちは、なかむら(う)です。

In message "[ruby-dev:40977] [Bug #812] Failure: test_priority (TestThread) on mswin32"
on Apr.14,2010 00:44:30, 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

=end

Actions #4

Updated by mame (Yusuke Endoh) almost 14 years ago

  • Status changed from Open to Closed

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0