I am trying to run 3 threads of a process using 3 sets of data. The
process is run from a class I made but for some reason when this certain
class method is called it seems to be getting the same data from each
thread. Here is the code I am using  to create the threads:

threads = []
breakfast = ['breakfast', '12:00:a', '11:00:a']
lunch = ['lunch', '11:01:a', '4:00:p']
dinner = ['dinner', '4:01:p', '11:59:p']
periods = [breakfast, lunch, dinner]
locations = [0,1,2,3,4,5]
for period in periods
  threads << Thread.new(period) {
    puts "This threads variables: #{period[0]} #{period[1]}
#{period[2]}"
    conn = Optim.new
    conn.connect('user', 'pass')
    res = conn.rtrvReport('SALES', date, date, period[1], period[2],
"C:\\Reporter\\data\\#{period[0]}_#{date.gsub('/','-')}.txt", locations)
    if res
      puts "Retrieved #{period[0]}_#{date.gsub('/','-')}"
    else
      puts "Failed on #{period[0]}_#{date.gsub('/','-')}"
    end
  }
end
threads.each { |aThread| aThread.join }

The rtrvReport method isnt fully implemented but I am trying to simply
print out the sTime variable to make sure each thread is passing a
different sTime. Here is what I have:

def rtrvReport(reportType, sDate, eDate, sTime, eTime, reportPath,
locations)
  puts "Got this: #{sTime}"
end

sTime is passed from period[1]. The problem is even though in my for
loop for the thread creation it is reporting the correct variables but
in this little output statement it is printing the same variable. So how
can each thread be passing this method different variables but each time
it prints out the same one!?!? Here is sample output:

This threads variables: breakfast 12:00:a 11:00:a
This threads variables: breakfast 11:01:a 4:00:p
This threads variables: breakfast 4:01:p 11:59:p
Got this: 4:01:p
Got this: 4:01:p
Got this: 4:01:p

So any ideas on why this is? Also, anyone know a shorter/cleaner way to
setup the 4 arrays of data I'm using for the threads?
Thanks,
-Alex

-- 
Posted via http://www.ruby-forum.com/.