I call the same Ruby function with multiple threads (e.g. 10 threads). Each thread passes different arguments to the function.
Example:
def test thread_no
puts "In thread no." + thread_no.to_s
end
num_threads = 6
threads=[]
for thread_no in 1..num_threads
puts "Creating thread no. "+thread_no.to_s
threads << Thread.new{test(thread_no)}
end
threads.each { |thr| thr.join }
Conclusion: Creating a stream. 1 Create a stream. 2 Create a stream. 3 Create a stream. 4 Topic 4:
Creating a stream. 5 Create a stream. 6 Topic β6
Topic β6
Topic β6
Topic β6
In stream β6
Of course, I want to get the output: In thread no. 1 (2,3,4,5,6) Can I somehow make it work?
source
share