#!/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