Ruby:
- Added a mutex to the @queue.empty logic in threading_queue.rb (lines 22-25), because it probably should be an atomic operation. This means that if multiple threads are acting on the queue, between the @queue.empty? check and the @queue.pop statement, there should be no opportunity for another thread to modify the queue.
- Started working on a thread pool for multiple parsers/downloaders, but I'm kind of stuck
- I'm not sure what data structure I should store the different parse threads in, and how to make the best use of them. For example, if there are 20 things in the parse queue and only 10 threads to handle them, how can the program get notified when a thread has completed its task so that I can assign it to the next item in the queue?
Code:
file = @lock.synchronize do
puts "Waiting for queue" if @queue.empty?
@queue.pop # this method is blocking if @queue is empty
end
Cool! I'm enjoying getting to look at Ruby code. Looks like a fun language to program in.
ReplyDelete