[#12543] Ruby Conference 0.3 — greentea@...2.so-net.ne.jp (Tomoyuki Kosimizu)

こんにちは、こしみずです。

21 messages 1999/03/04
[#12570] Re: Ruby Conference 0.3 — matz@... (Yukihiro Matsumoto) 1999/03/05

まつもと ゆきひろです

[#12571] Re: Ruby Conference 0.3 — Takaaki Higuchi - Technology Marketing <Takaaki.Higuchi@...> 1999/03/05

> | >18日あたり東京でRuby Conference 0.3(単なる宴会)を開きましょうか?

[#12577] Re: Ruby Conference 0.3 — matz@... (Yukihiro Matsumoto) 1999/03/05

まつもと ゆきひろです

[#12645] Re: Ruby Conference 0.3 — KIMURA Koichi <kimura@...> 1999/03/08

[#12546] [閑話] Ruby Conference 0.3 参加したいぃ — Atsuko Yoshida <atsuko@...>

こんにちは。あつこです。

17 messages 1999/03/05
[#12548] Re: [ 閑話] Ruby Conference 0.3 参加したいぃ — KIMURA Koichi <kimura@...> 1999/03/05

[#12573] alternative name of iterator — Shugo Maeda <shugo@...>

前田です。

49 messages 1999/03/05
[#12584] Re: alternative name of iterator — matz@... (Yukihiro Matsumoto) 1999/03/05

まつもと ゆきひろです

[#12641] Re: alternative name of iterator — moochan <moochan@...> 1999/03/08

moochan です.

[#12642] Re: alternative name of iterator — matz@... (Yukihiro Matsumoto) 1999/03/08

まつもと ゆきひろです

[#12643] Re: alternative name of iterator — moochan <moochan@...> 1999/03/08

moochan です.

[#12644] Re: alternative name of iterator — matz@... (Yukihiro Matsumoto) 1999/03/08

まつもと ゆきひろです

[#12661] Re: alternative name of iterator — moochan <moochan@...> 1999/03/09

moochan です.

[#12662] Re: alternative name of iterator — matz@... (Yukihiro Matsumoto) 1999/03/09

まつもと ゆきひろです

[#12666] Re: alternative name of iterator — moochan <moochan@...> 1999/03/09

moochan です.

[#12590] kconv SJIS — Kikutani Makoto <kikutani@...>

=?ISO-2022-JP?B? ではじまるBエンコードされたサブジェクトは

20 messages 1999/03/06

[#12695] 第 2 回 OMG 分散コンピューティング・セミナー: CORBA3.0 の詳説と CORBA 活用の実際 — Junichi Suzuki <jun-sk@...>

各位.

19 messages 1999/03/10
[#12911] HORB for Ruby? — Shugo Maeda <shugo@...> 1999/03/16

前田です。

[#12707] Re: operater bind order ? — Inaba Hiroto <inaba@...>

稲葉です.

16 messages 1999/03/10
[#12709] Re: operater bind order ? — KIMURA Koichi <kimura@...> 1999/03/10

[#12727] Making of Interval class. — moochan <moochan@...>

moochan です.

40 messages 1999/03/10
[#12742] Re: Making of Interval class. — Shugo Maeda <shugo@...> 1999/03/11

前田です。

[#12746] Re: Making of Interval class. — moochan <moochan@...> 1999/03/11

moochan です.

[#12728] Time + 1M — Wakou Aoyama <wakou@...>

青山です。

30 messages 1999/03/10
[#12731] Re: Time + 1M — Tadayoshi Funaba <tadf@...> 1999/03/10

ふなばです。

[#12772] Re: Time + 1M — IKARASHI Akira <ikarashi@...> 1999/03/11

五十嵐です。

[#12774] Re: Time + 1M — Tadayoshi Funaba <tadf@...> 1999/03/11

ふなばです。

[#12775] Re: Time + 1M — IKARASHI Akira <ikarashi@...> 1999/03/11

五十嵐です。

[#12850] Ruby Conference 0.3 where ? when ? — ISII takesi <isii@...>

石井です。

89 messages 1999/03/15
[#12852] Re: Ruby Conference 0.3 where ? when ? — matz@... (Yukihiro Matsumoto) 1999/03/15

まつもと ゆきひろです

[#12859] Re: Ruby Conference 0.3 where ? when ? — hisanori@... 1999/03/15

松尾です。

[#12860] Re: Ruby Conference 0.3 where ? when ? — matz@... (Yukihiro Matsumoto) 1999/03/15

まつもと ゆきひろです

[#12861] Re: Ruby Conference 0.3 where ? when ? — hisanori@... 1999/03/15

松尾です。

[#12862] Re: Ruby Conference 0.3 where ? when ? — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/15

なひです.

[#12864] Re: Ruby Conference 0.3 where ? when ? — matz@... (Yukihiro Matsumoto) 1999/03/15

まつもと ゆきひろです

[#12870] Re: Ruby Conference 0.3 where ? when ? — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/15

なひです.

[#12872] Re: Ruby Conference 0.3 where ? when ? — matz@... (Yukihiro Matsumoto) 1999/03/15

まつもと ゆきひろです

[#12888] signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/15

なひです.

[#12896] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — matz@... (Yukihiro Matsumoto) 1999/03/16

まつもと ゆきひろです

[#12960] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/17

なひです.

[#12962] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — 中村暁史 <anakamur@...> 1999/03/17

[#12993] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/18

なひです.

[#12995] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — 中村暁史 <anakamur@...> 1999/03/18

[#13009] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/19

なひです.

[#13010] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/19

なひです.

[#13011] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — KIMURA Koichi <kimura@...> 1999/03/19

[#13013] Re: signal handler in Ruby( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/19

なひです.

[#13016] Re: signal handler in Ruby( was Re: Ruby Conference 0.3 where ? when ? ) — 中村暁史 <anakamur@...> 1999/03/19

[#13023] Re: signal handler in Ruby( was Re: Ruby Conference 0.3 where ? when ? ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/03/19

なひです.

[#13012] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — 中村暁史 <anakamur@...> 1999/03/19

[#13037] Re: signal handler in Ruby ( was Re: Ruby Conference 0.3 where ? when ? ) — keiju@... (石塚圭樹 ) 1999/03/20

けいじゅ@日本ラショナルソフトウェアです.

[#12918] Sieve of Eratosthenes (Re: [ruby-dev:6094]) — Shin-ichiro Hara <sinara@...>

原です。

29 messages 1999/03/16
[#12924] delete during each (Re: Sieve of Eratosthenes) — matz@... (Yukihiro Matsumoto) 1999/03/17

まつもと ゆきひろです

[#12930] Re: delete during each (Re: Sieve of Eratosthenes) — Shin-ichiro Hara <sinara@...> 1999/03/17

原です。

[#12932] Re: delete during each (Re: Sieve of Eratosthenes) — matz@... (Yukihiro Matsumoto) 1999/03/17

まつもと ゆきひろです

[#12934] Re: delete during each (Re: Sieve of Eratosthenes) — Shin-ichiro Hara <sinara@...> 1999/03/17

原です。

[#13091] FAQ for /:|) — matz@... (Yukihiro Matsumoto)

まつもと ゆきひろです

17 messages 1999/03/23

[#13121] 全角文字列の分割方法について — goto@...

初めまして、後藤@横河工事(橋梁技術者)です。

17 messages 1999/03/24
[#13122] Re: 全角文字列の分割方法について — matz@... (Yukihiro Matsumoto) 1999/03/24

まつもと ゆきひろです

[#13123] Re: 全角文字列の分割方法について — goto@... 1999/03/24

後藤@横河工事(橋梁技術者)です。お世話になります。

[#13134] ロックでアドバイスをいただきたいのですが — Keisuke Minami <keisuke@...>

はじめまして。三並と申します。

30 messages 1999/03/24
[#13136] Re: ロックでアドバイスをいただきたいのですが — hisanori@... 1999/03/24

松尾です。

[#13139] Re: ロックでアドバイスをいただきたいのですが — 中村暁史 <anakamur@...> 1999/03/24

[#13188] CGI (Re: ロックでアドバイスをいただきたいのですが) — Shugo Maeda <shugo@...> 1999/03/25

前田です。

[#13190] Re: CGI (Re: ロックでアドバイスをいただきたいのですが) — hisanori@... 1999/03/25

松尾です。

[#13140] Ruby Conference 0.3 — hisanori@...

松尾です。

25 messages 1999/03/24

[ruby-list:12498] monitor.rb

From: Shugo Maeda <shugo@...>
Date: 1999-03-01 11:03:18 UTC
List: ruby-list #12498
前田です。

1.3用にmonitor.rbを書き直しました。
すべてのオブジェクトがインスタンス変数を持てるようになったお
かげで、Rubyレベルではfinalizerの必要性はなくなったと考えて
よいかもしれませんね。
Rubyではファイルなどの非メモリリソースもCレベルのfinalizerが
面倒を見てくれますし。

あと、instance_evalを使わなくてもカプセル化ができるように工
夫しました。
Mixinをアクセス指定に使う例はたぶんはじめてだと思います。
# なぜならprotectedにバグがあったから(^_^;


-- 
前田 修吾

Attachments (1)

monitor.rb (3.83 KB, text/x-ruby)
=begin

monitor.rb
Author: Shugo Maeda <shugo@netlab.co.jp>
Version: 1.2

USAGE:

  foo = Foo.new
  foo.extend(MonitorMixin)
  cond = foo.new_cond

  thread1:
  foo.synchronize {
    ...
    cond.wait_until { foo.done? }
    ...
  }

  thread2:
  foo.synchronize {
    foo.do_something
    cond.signal
  }

=end
  
module MonitorMixin
  module Accessible
  protected
    attr_accessor :mon_owner, :mon_count
    attr_reader :mon_entering_queue, :mon_waiting_queue
  end
  
  module Initializable
  protected
    def mon_initialize
      @mon_owner = nil
      @mon_count = 0
      @mon_entering_queue = []
      @mon_waiting_queue = []
    end
  end
  
  class ConditionVariable
    include Accessible
    
    def wait
      if @monitor.mon_owner != Thread.current
	raise ThreadError, "current thread not owner"
      end
      
      Thread.critical = true
      count = @monitor.mon_count
      @monitor.mon_count = 0
      @monitor.mon_owner = nil
      if @monitor.mon_waiting_queue.empty?
	t = @monitor.mon_entering_queue.shift
      else
	t = @monitor.mon_waiting_queue.shift
      end
      t.wakeup if t
      @waiters.push(Thread.current)
      Thread.stop
      
      Thread.critical = true
      while @monitor.mon_owner != nil &&
	  @monitor.mon_owner != Thread.current
	@monitor.mon_waiting_queue.push(Thread.current)
	Thread.stop
	Thread.critical = true
      end
      @monitor.mon_owner = Thread.current
      @monitor.mon_count = count
      Thread.critical = false
    end
    
    def wait_while
      while yield
	wait
      end
    end
    
    def wait_until
      until yield
	wait
      end
    end
    
    def signal
      if @monitor.mon_owner != Thread.current
	raise ThreadError, "current thread not owner"
      end
      Thread.critical = true
      t = @waiters.shift
      t.wakeup if t
      Thread.critical = false
      Thread.pass
    end
    
    def broadcast
      if @monitor.mon_owner != Thread.current
	raise ThreadError, "current thread not owner"
      end
      Thread.critical = true
      for t in @waiters
	t.wakeup
      end
      @waiters.clear
      Thread.critical = false
      Thread.pass
    end
    
    def count_waiters
      return @waiters.length
    end
    
  private
    def initialize(monitor)
      @monitor = monitor
      @waiters = []
    end
  end
  
  include Accessible
  include Initializable
  extend Initializable
  
  def self.extend_object(obj)
    super(obj)
    obj.mon_initialize
  end
  
  def try_mon_enter
    result = false
    Thread.critical = true
    if mon_owner.nil?
      self.mon_owner = Thread.current
    end
    if mon_owner == Thread.current
      self.mon_count += 1
      result = true
    end
    Thread.critical = false
    return result
  end

  def mon_enter
    Thread.critical = true
    while mon_owner != nil && mon_owner != Thread.current
      mon_entering_queue.push(Thread.current)
      Thread.stop
      Thread.critical = true
    end
    self.mon_owner = Thread.current
    self.mon_count += 1
    Thread.critical = false
  end
  
  def mon_exit
    if mon_owner != Thread.current
      raise ThreadError, "current thread not owner"
    end
    Thread.critical = true
    self.mon_count -= 1
    if mon_count == 0
      self.mon_owner = nil
      if mon_waiting_queue.empty?
	t = mon_entering_queue.shift
      else
	t = mon_waiting_queue.shift
      end
    end
    t.wakeup if t
    Thread.critical = false
    Thread.pass
  end

  def mon_synchronize
    mon_enter
    begin
      yield
    ensure
      mon_exit
    end
  end
  alias synchronize mon_synchronize
  
  def new_cond
    return ConditionVariable.new(self)
  end
  
private
  def initialize(*args)
    super
    mon_initialize
  end
end

class Monitor
  include MonitorMixin
  alias try_enter try_mon_enter
  alias enter mon_enter
  alias exit mon_exit
  alias owner mon_owner
end

# Local variables:
# mode: Ruby
# tab-width: 8
# End:

In This Thread

Prev Next