Skip to content

Commit

Permalink
added programs to create many threads programatically
Browse files Browse the repository at this point in the history
  • Loading branch information
mindaslab committed Sep 18, 2014
1 parent ff6aedc commit b63cc32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions many_threads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# many_threads.rb

def launch_thread string
thread = Thread.new do
3.times do
puts string
sleep rand(3)
end
end
return thread
end

threads = []
threads << launch_thread("Hi")
threads << launch_thread("Hello")

threads.each {|t| t.join}

20 changes: 20 additions & 0 deletions many_threads_1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# many_threads_1.rb

def launch_thread string
thread = Thread.new do
3.times do
puts string
sleep rand(3)
end
end
return thread
end

threads = []

4.times do |i|
threads << launch_thread("Thread #{i}")
end

threads.each {|t| t.join}

0 comments on commit b63cc32

Please sign in to comment.