From: shugo@... (Shugo Maeda) Date: 1998-02-26T21:04:16+09:00 Subject: [ruby-list:6795] Re: Mutex/ConditionVariable/Queue 前田です。 In message "[ruby-list:6794] Re: Mutex/ConditionVariable/Queue" Shugo Maeda wrote: |Mutex#__cond_lockというのが苦しいところです。 |C++ならfriendにするんでしょうね(^^; Mutx.instance_methodsで__cond_lockが出てくるのはちょっとくやしい のでRuby流(?)に解決してみました。 -- 前田 修吾 --- threadlib.rb~ Thu Feb 26 20:24:14 1998 +++ threadlib.rb Thu Feb 26 20:59:24 1998 @@ -55,16 +55,6 @@ unlock end end - - # DO NOT CALL THIS METHOD - def __cond_lock - while (Thread.critical = true; @owner != nil) - @cond_waiting.push(Thread.current) - Thread.stop - end - @owner = Thread.current - Thread.critical = false - end end class ConditionVariable @@ -80,7 +70,14 @@ @waiting.push(Thread.current) } Thread.stop - @mutex.__cond_lock + @mutex.instance_eval %{ + while (Thread.critical = true; @owner != nil) + @cond_waiting.push(Thread.current) + Thread.stop + end + @owner = Thread.current + Thread.critical = false + } end def signal