diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-27 15:51:24 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-27 15:51:24 +0200 |
commit | cd25485777d9525bd4b29ab350f1ff9e864cf015 (patch) | |
tree | 604703d26de51693f1ddd8a4a0ee35e347f18868 | |
parent | 6a5407b96d09b506d4f0bfb5dec0d435408c017d (diff) |
threads1
-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 + |