Project

General

Profile

Bug #15360 ยป deadlock_test.rb

Run with "ruby deadlock_test.rb" - brockspratlen (Brock Spratlen), 11/29/2018 06:09 PM

 
1
require "thread"
2
require "timeout"
3

    
4
class Hallo
5
  extend MonitorMixin
6

    
7
  def self.global_sleep(duration)
8
    self.mon_synchronize do
9
      sleep(duration)
10
    end
11
  end
12
end
13

    
14
threads = 20.times.collect do
15
  Thread.new do
16
    200.times do
17
      begin
18
        Timeout.timeout(0.1) do
19
          Hallo.global_sleep(0.2)
20
        end
21
      rescue ThreadError => e
22
        puts "#{e.class}: #{e.message}:\n" + e.backtrace.join("\n") + "\n\n"
23
      rescue Timeout::Error => e
24
        puts e.class
25
        nil
26
      end
27
    end
28
  end
29
end
30

    
31
threads.each{ |t| t.join }