diff options
-rwxr-xr-x | ruby/threads1.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/ruby/threads1.rb b/ruby/threads1.rb new file mode 100755 index 0000000..1136621 --- /dev/null +++ b/ruby/threads1.rb @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +require 'thread' + + +a = [] +threads = [] +mutex = Mutex.new +('a'..'r').each { |i| + threads << Thread.new(i) { |c| + mutex.synchronize { a << i } + } +} +threads.each { |t| t.join } + +puts a.to_s + |