P
Pete Kazmier
First the disclaimer: I'm a newbie to ruby
While looking at some of the standard libraries included in my ruby
distribution (1.8), I took particular interest in the thread.rb's
Queue implementation because I need to use it. However, I am not
certain that I understand why it is actually thread safe.
The implementation is essentially backed by an Array. Queue provides
synchronized push and pop methods (using Thread.critical), but methods
such as clear, length, and empty? are not synchronized. What happens
if one thread is in the middle of clearing the queue and then another
comes along to add/remove something from the queue? Why don't these
other methods need synchronization? Is Array thread-safe by default?
Thanks!
Pete
While looking at some of the standard libraries included in my ruby
distribution (1.8), I took particular interest in the thread.rb's
Queue implementation because I need to use it. However, I am not
certain that I understand why it is actually thread safe.
The implementation is essentially backed by an Array. Queue provides
synchronized push and pop methods (using Thread.critical), but methods
such as clear, length, and empty? are not synchronized. What happens
if one thread is in the middle of clearing the queue and then another
comes along to add/remove something from the queue? Why don't these
other methods need synchronization? Is Array thread-safe by default?
Thanks!
Pete