Debian Codegraph @

sample/thread.rb

raw
1 $:.unshift(File.join('..', 'lib'))
2 require 'httpclient'
3
4 urlstr = ARGV.shift
5
6 proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
7 h = HTTPClient.new(proxy)
8
9 count = 20
10
11 res = []
12 g = []
13 for i in 0..count
14 g << Thread.new {
15 res[i] = h.get(urlstr)
16 }
17 end
18
19 g.each do |th|
20 th.join
21 end
22
23 for i in 0..(count - 1)
24 raise unless (res[i].content == res[i + 1].content)
25 end
26
27 puts 'ok'