[#6214] RE^2: HTML class — 青山 和光 <PXN11625@...>
In-Reply-To: [ruby-list:6118] Re: HTML class
[#6219] Ruby連載 第4話 — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
原です。
まつもと ゆきひろです
原です。
ももちゃん@あるもにこすです.
まつもと ゆきひろです
In message <199802040557.OAA18458@picachu.netlab.co.jp>
まつもと ゆきひろです
In message <199802040739.QAA20750@picachu.netlab.co.jp>
まつもと ゆきひろです
In message <199802040803.RAA24375@picachu.netlab.co.jp>
[#6249] Re: i++ — 助田 雅紀 <masaki.suketa@...>
助田です。
ことけんです
まつもと ゆきひろです
しげひろです.
ももちゃん@あるもにこすです.
まつもと ゆきひろです
ももちゃん@あるもにこすです.
まつもと ゆきひろです
[#6256] pop & smtp-lib.rb — tateishi@... (Takaaki TATEISHI)
立石@理科大です。
[#6272] I'd like to subscribe this ML — INOUE Katsuyuki <inoue@...>
井上勝行 と申します。
[#6279] Re: i++ — 助田 雅紀 <masaki.suketa@...>
助田です。
[#6314] RE: ruby's design policy (Re: I'd like to subscr ibe this ML) — 助田 雅紀 <masaki.suketa@...>
オブジェクト指向周辺をぶらぶらしている助田です。
まつもと ゆきひろです
井上勝行です。
まつもと ゆきひろです
[#6315] install some versions — gotoken@... (GOTO Kentaro)
ごとけんです
[#6333] ruby 流に添削して下さい — nkon@...2.3web.ne.jp
さくです.
さくです.自己フォロー.
まつもと ゆきひろです
わたなべです.
まつもと ゆきひろです
わたなべです.
[#6342] Re: ruby's design policy (Re: I'd like to su bscr ibe this ML) — 助田 雅紀 <masaki.suketa@...>
助田です。
[#6372] ruby 1.1b7 released — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
前田です。
わたなべです.
ふなばです。
まつもと ゆきひろです
ふなばです。
[#6373] call for scripts — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
> もっと良いものがあるかもしれないと考え,実例集に載せられるよ
sort-schedule.rbで、ちょっと疑問に思っていることがあるのです
金城です.
まつもと ゆきひろです
金城です.
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
原です。
From: Shin-ichiro HARA <sinara@blade.nagaokaut.ac.jp>
きくたに@ぷ〜たろ〜です。
さくです.
わたなべです.
まつもと ゆきひろです
前田です。
前田です。
まつもと ゆきひろです
前田です。
前田です。
前田です。
前田です。
わたなべです.
ふなばです。
In message <19980222011624S.tadf@kt.rim.or.jp>
前田です。
ふなばです。
ふなばです。
けいじゅ@日本ラショナルソフトウェアです.
Regard to "[ruby-list:7447] Re: call for scripts"
[#6422] simple_chat_server — 青山 和光 <PXN11625@...>
In-Reply-To: [ruby-list:6395] Re: call for scripts
[#6447] gsub — Tadayoshi Funaba <tadf@...>
ふなばです。
[#6514] ROT13/47 — OZAWA Sakuro <crouton@...>
小澤さくです.
[#6516] RE^2: simple_chat_server — 青山 和光 <PXN11625@...>
In-Reply-To: [ruby-list:6437] Re: simple_chat_server
まつもと ゆきひろです
class String; def - x; end; end; %-
[#6538] IE favorites to HTML — OZAWA Sakuro <ozawa@...>
小澤さくです。会社からもMLに入っちゃいます。
[#6565] Re: Counter class [Re: i++ ] — toyofuku@...
豊福@パパイヤです。
[#6582] File::Separator on cygwin — OZAWA Sakuro <ozawa@...>
小澤さくです。
わたなべです.
小澤さくです。
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
[#6591] ruby 1.1b8 released — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
前田です。
けいじゅ@日本ラショナルソフトウェアです.
前田です。
けいじゅ@日本ラショナルソフトウェアです.
まつもと ゆきひろです
さくです.
前田です。
小澤さくです。
うさぎの名前ででています:-)
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
まつもと ゆきひろです
[#6601] 8-queen — TAKAHASHI Masayoshi <maki@...>
高橋です。今度ちゃんと1.1b7にします……と書こうとしたら、b8になって
[#6605] true/TRUE false/FALSE nil/NIL — OZAWA Sakuro <crouton@...>
小澤さくです.
前田です。
まつもと ゆきひろです
[#6610] tcltklib dosen't compile — TEI meiki <tei@...>
鄭です。
[#6621] here document — Tadayoshi Funaba <tadf@...>
ふなばです。
[#6635] hello — WATANABE Tetsuya <tetsu@...>
渡辺哲也と申します。
まつもと ゆきひろです
>>>>> "matz" == Yukihiro Matsumoto <matz@netlab.co.jp> writes:
[#6706] Re: Counter class — toyofuku@...
豊福@パパイヤです。
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
[#6735] Mutex/ConditionVariable/Queue — shugo@... (Shugo Maeda)
前田です。
まつもと ゆきひろです
けいじゅ@日本ラショナルソフトウェアです.
前田です。
From: shugo@po.aianet.ne.jp (Shugo Maeda)
前田です。
From: shugo@po.aianet.ne.jp (Shugo Maeda)
前田です。
まつもと ゆきひろです
[#6786] Re: Mutex/ConditionVariable/Queue — senda@...
From: shugo@po.aianet.ne.jp (Shugo Maeda)
前田です。
前田です。
前田です。
けいじゅ@日本ラショナルソフトウェアです.
In message <199802261520.AAA18702.keiju@cupmail0.rational.com>
前田です。
In message <199802270237.CAA00362@soleil.localnet.or.jp>
前田です。
In message <199802270635.GAA00354@soleil.localnet.or.jp>
前田です。
[#6819] ruby 1.1b9 released — matz@... (Yukihiro Matsumoto)
まつもと ゆきひろです
[#6829] monitor.rb — shugo@... (Shugo Maeda)
前田です。
[#6830] what is 'octet decimal' — OZAWA Sakuro <crouton@...>
さくです.
[#6852] Counting Semaphore — Kazuhisa YANAGAWA <katze@...>
Counting semaphore をちょっと作ってみました. 見ての通り, コードは
[ruby-list:6796] Re: Mutex/ConditionVariable/Queue
けいじゅ@日本ラショナルソフトウェアです.
In [ruby-list :06794 ] the message: "[ruby-list:6794] Re:
Mutex/ConditionVariable/Queue ", on Feb/26 20:42(JST) Shugo Maeda
writes:
>前田です。
>実際に実装してみました。
>SizedQueueもConditionVariableを使って書いてみましたが、きちんと
>動作確認していないのでうまく動くかわかりません(^^;
>
>Mutex#__cond_lockというのが苦しいところです。
>C++ならfriendにするんでしょうね(^^;
それもありますが. 本来必要のない実装がMutexに入り込んでいますよね.
この場合は, MutexのサブクラスとしてConditionVariableに必要な機能を持つ
ものを実装した方が良くないでしょうか? すると, Mutex#__cond_lock ->
ConditionMutex#lock となって気持ち良くoverloadできますしね.
ついでに, そのサブクラスをConditionVariableのスコープに入れてしまいま
す.
さらに, ConditionVariable.newでmutexを渡すようになっていますが, 外部か
ら渡した方が良いんですかね? 勝手に必要がないとしてinitializeの中に組み
込んでみました.
# 必要ならば, ConditionVariable::ConditionMutex.new を行なう必要が出てく
# るので, もうちょっと工夫の必要があるかな?
すると以下のようなプログラムになりました. いかがなものでしょう?
# やっぱり動作確認しておりません.
class Mutex
# オリジナルMutexと同じ
end
class ConditionVariable
class ConditionMutex
attr :owner
def initialize
super
@cond_waiting = []
@owner = nil
end
def try_lock
if ret = super
@owner = Thread.current
end
ret
end
def lock
while (Thread.critical = true; @owner != nil)
@cond_waiting.push(Thread.current)
Thread.stop
end
@owner = Thread.current
Thread.critical = false
end
def unlock
if @owner != Thread.current
raise ThreadError, "current thread not owner"
end
Thread.critical = true
if @cond_waiting.empty?
t = @waiting.shift
else
t = @cond_waiting.shift
end
@owner = nil
Thread.critical = false
t.run if t
end
end
def initialize
@mutex = ConditionMutex.new
@waiting = []
@waiting_mutex = Mutex.new
end
def synchronize
@mutex.syncronize do
yield
end
end
def wait
@mutex.unlock
@waiting_mutex.synchronize {
@waiting.push(Thread.current)
}
Thread.stop
@mutex.lock
end
def signal
if @mutex.owner != Thread.current
raise ThreadError, "current thread not owner"
end
@waiting_mutex.synchronize {
t = @waiting.shift
t.run if t
}
end
def broadcast
if @mutex.owner != Thread.current
raise ThreadError, "current thread not owner"
end
@waiting_mutex.synchronize {
for t in @waiting
t.run
end
@waiting.clear
}
end
def num_waiting
return @waiting.length
end
end
class Queue
def initialize
@que = []
@que_cond = ConditionVariable.new
end
def push(obj)
@que_cond.synchronize {
@que.push(obj)
@que_cond.signal
}
end
def pop(noblock = false)
@que_cond.synchronize {
if noblock and @que.length == 0
raise ThreadError, "queue empty"
end
while @que.empty?
@que_cond.wait
end
return @que.shift
}
end
def empty?
@que.length == 0
end
def length
@que.length
end
alias size length
def num_waiting
return @que_cond.num_waiting
end
end
class SizedQueue < Queue
attr :max
def initialize(max)
@max = max
@sized_que_cond = ConditionVariable.new
super()
end
def push(obj)
@sized_que_cond.synchronize {
while @que.length >= @max
@sized_que_cond.wait
end
super(obj)
}
end
def pop(*args)
@sized_que_cond.synchronize {
obj = super
if @que.length < @max
@sized_que_cond.signal
end
return obj
}
end
def max=(max)
@sized_que_cond.synchronize {
@max = max
@sized_que_cond.broadcast
}
end
def num_waiting
return super + @sized_que_cond.num_waiting
end
end
>
>class Mutex
>
> attr :owner
>
> def initialize
> @waiting = []
> @cond_waiting = []
> @owner = nil
> end
>
> def locked?
> return @owner != nil
> end
>
> def try_lock
> result = false
> Thread.critical = true
> if @owner.nil?
> @owner = Thread.current
> result = true
> end
> Thread.critical = false
> return result
> end
>
> def lock
> while (Thread.critical = true; @owner != nil)
> @waiting.push(Thread.current)
> Thread.stop
> end
> @owner = Thread.current
> Thread.critical = false
> end
>
> def unlock
> if @owner != Thread.current
> raise ThreadError, "current thread not owner"
> end
> Thread.critical = true
> if @cond_waiting.empty?
> t = @waiting.shift
> else
> t = @cond_waiting.shift
> end
> @owner = nil
> Thread.critical = false
> t.run if t
> end
>
> def synchronize
> begin
> lock
> yield
> ensure
> 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
> def initialize(mutex)
> @mutex = mutex
> @waiting = []
> @waiting_mutex = Mutex.new
> end
>
> def wait
> @mutex.unlock
> @waiting_mutex.synchronize {
> @waiting.push(Thread.current)
> }
> Thread.stop
> @mutex.__cond_lock
> end
>
> def signal
> if @mutex.owner != Thread.current
> raise ThreadError, "current thread not owner"
> end
> @waiting_mutex.synchronize {
> t = @waiting.shift
> t.run if t
> }
> end
>
> def broadcast
> if @mutex.owner != Thread.current
> raise ThreadError, "current thread not owner"
> end
> @waiting_mutex.synchronize {
> for t in @waiting
> t.run
> end
> @waiting.clear
> }
> end
>
> def num_waiting
> return @waiting.length
> end
>end
>
>class Queue
> def initialize
> @que = []
> @que_mutex = Mutex.new
> @que_cond = ConditionVariable.new(@que_mutex)
> end
>
> def push(obj)
> @que_mutex.synchronize {
> @que.push(obj)
> @que_cond.signal
> }
> end
>
> def pop(noblock = false)
> @que_mutex.synchronize {
> if noblock and @que.length == 0
> raise ThreadError, "queue empty"
> end
> while @que.empty?
> @que_cond.wait
> end
> return @que.shift
> }
> end
>
> def empty?
> @que.length == 0
> end
>
> def length
> @que.length
> end
> alias size length
>
> def num_waiting
> return @que_cond.num_waiting
> end
>end
>
>class SizedQueue < Queue
>
> attr :max
>
> def initialize(max)
> @max = max
> @sized_que_mutex = Mutex.new
> @sized_que_cond = ConditionVariable.new(@sized_que_mutex)
> super()
> end
>
> def push(obj)
> @sized_que_mutex.synchronize {
> while @que.length >= @max
> @sized_que_cond.wait
> end
> super(obj)
> }
> end
>
> def pop(*args)
> @sized_que_mutex.synchronize {
> obj = super
> if @que.length < @max
> @sized_que_cond.signal
> end
> return obj
> }
> end
>
> def max=(max)
> @sized_que_mutex.synchronize {
> @max = max
> @sized_que_cond.broadcast
> }
> end
>
> def num_waiting
> return super + @sized_que_cond.num_waiting
> end
>end
>
>--
>前田 修吾
>
__
................................石塚 圭樹@日本ラショナルソフトェア...
----------------------------------->> e-mail: keiju@rational.com <<---