From cd25485777d9525bd4b29ab350f1ff9e864cf015 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Fri, 27 Jun 2014 15:51:24 +0200 Subject: threads1 --- ruby/threads1.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 ruby/threads1.rb (limited to 'ruby/threads1.rb') 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 + -- cgit v1.2.3