diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:13:14 +0000 |
commit | d0233291bc8a5068e52c69c210e5979e5324b5bc (patch) | |
tree | 7d9459449c33792c63eeb7baa071e76352e0baab /trunk/sample/drb/simpletuple.rb | |
parent | 0dc342de848a642ecce8db697b8fecd83a63e117 (diff) | |
parent | 72eaacaa15256ab95c3b52ea386f88586fb9da40 (diff) |
re-adding tag v1_9_0_4 as an alias of trunk@18848v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/sample/drb/simpletuple.rb')
-rw-r--r-- | trunk/sample/drb/simpletuple.rb | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/trunk/sample/drb/simpletuple.rb b/trunk/sample/drb/simpletuple.rb deleted file mode 100644 index 3ae9208c79..0000000000 --- a/trunk/sample/drb/simpletuple.rb +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/local/bin/ruby -# SimpleTupleSpace -# Copyright (c) 1999-2000 Masatoshi SEKI -# You can redistribute it and/or modify it under the same terms as Ruby. - -require 'thread' - -class SimpleTupleSpace - def initialize - @hash = {} - @waiting = {} - @hash.taint - @waiting.taint - self.taint - end - - def out(key, obj) - Thread.critical = true - @hash[key] ||= [] - @waiting[key] ||= [] - @hash[key].push obj - begin - t = @waiting[key].shift - @waiting.delete(key) if @waiting[key].length == 0 - t.wakeup if t - rescue ThreadError - retry - ensure - Thread.critical = false - end - end - - def in(key) - Thread.critical = true - @hash[key] ||= [] - @waiting[key] ||= [] - begin - loop do - if @hash[key].length == 0 - @waiting[key].push Thread.current - Thread.stop - else - return @hash[key].shift - end - end - ensure - @hash.delete(key) if @hash[key].length == 0 - Thread.critical = false - end - end -end - -if __FILE__ == $0 - ts = SimpleTupleSpace.new - clients = [] - servers = [] - - def server(ts) - Thread.start { - loop do - req = ts.in('req') - ac = req[0] - num = req[1] - ts.out(ac, num * num) - end - } - end - - def client(ts, n) - Thread.start { - ac = Object.new - ts.out('req', [ac, n]) - ans = ts.in(ac) - puts "#{n}: #{ans}" - } - end - - 3.times do - servers.push(server(ts)) - end - - (1..6).each do |n| - clients.push(client(ts, n)) - end - - clients.each do |t| - t.join - end -end - - |