Hi, I am using threads to do some calculations and I would like some
help.
I have a function named “myfun(i,k)” which creates within its body some
arrays and does a bunch of stuff with them and returns an integer.
Then I create a second function named “seeder(k)” which does the
threading:
def seeder(k)
threads = []
result = []
for i in (1…k)
threads << Thread.new(i){
res << myfun(i, k)
}
end
threads.each {|t| t.join }
return result.min
end
I also posted the code here: http://pastebin.com/khM2qrgG
The above code does not give the correct results when I check it with
the serial version.
So how do I create an array as a local variable to function “seeder”
shared to the threads so that each thread puts its result to the array
and then I return the minimum of that array ?
I could not find an example of “Thread.current” and a shared array.
If it ain’t that easy maybe I could create a global array but I prefer
the local shared one.
PS: The local variables for each call of “myfun” within the threads
remain local to the call, right ?