用 params 传文件名 然后 send_file 就行了
so so so cool!!
require 'thread'
mutex = Mutex.new
cv = ConditionVariable.new
arr = [1, 2, 3, 4, 5, 6, 7, 8]
thread =[]
thread<< Thread.new do
mutex.synchronize do
arr.each { |a|
@value = a
cv.broadcast
cv.wait(mutex)
}
end
end
thread<< Thread.new do
mutex.synchronize do
while thread[0].alive?
puts @value
cv.wait(mutex)
end
end
end
thread<< Thread.new do
mutex.synchronize do
while thread[0].alive?
puts @value
cv.signal if Thread.list.pop==Thread.current
cv.wait(mutex)
end
end
end
thread<< Thread.new do
mutex.synchronize do
while thread[0].alive?
puts @value
cv.signal if Thread.list.pop==Thread.current
cv.wait(mutex)
end
end
end
sleep 2
########################################
1
1
1
2
2
2
3
3
3
4
4
4
5
5
5
6
6
6
7
7
7
8
8
8
Process finished with exit code 0