-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.rb
45 lines (39 loc) · 819 Bytes
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'travis/lock'
require 'redlock'
@options ||= {
strategy: :redis,
url: ENV['REDIS_URL'] || 'redis://localhost:6379',
retries: 0
}
def thrFunc(idx)
puts "thr_#{idx}++"
done = false
loop do
done == false || break
begin
Travis::Lock.exclusive('locklock', @options) do
puts "thr_#{idx} has lock"
n = 10
while n > 0 do
puts "#{idx}: #{n}"
n -=1
sleep(0.41)
end
done = true
end
rescue Travis::Lock::Redis::LockError => e
puts "thr_#{idx} ERROR : #{e.message}"
end
# sleep(0.1)
end
puts "thr_#{idx}--"
end
threads=Array.new
(0..10).each do |i|
threads << Thread.new {thrFunc i }
end
threads.each do |thr|
puts 'join ' + thr.object_id.to_s
thr.join
puts "thr_"+thr.object_id.to_s
end