From: Marcin Raczkowski Date: 2007-06-01T19:52:44+09:00 Subject: Re: DRb and Thread safety On Friday 01 June 2007 09:42, Erwin Abbott wrote: > Marcin and Brian, > > Thank you for the help, I feel like I have a pretty good starting > place now to figure the details out myself. I'm still not sure what > the differences between all the data structures like Mutex, Condition > Variable, Semaphore, Monitor, etc are... but I can work that out. Mutex - is block that can't be run concurently Semaphore - is like "stop" sign - execution will stop untill semaphore is lifted in another thread Monitor - is class that throught specially made accessors allows only synchronous access to it's methods/variables (Queue class in standard lib is good example) Condition Variable is something oposite to Semaphore > > On 5/31/07, Brian Candler wrote: > > This is where a good book comes in. There are some relevant articles on > > wikipedia. Googling for "philosophers" and "spaghetti" may also be > > helpful :-) > > Yes, very helpful. It also led me to: > - Sleeping barber problem > - Cigarette smokers problem > - Dining cryptographers protocol all these algorithms are very complicated in c - but in ruby are usually really easy - you only need to use thread safe classes (like Queue) or Monitor mixin for example in ruby solving Writers and Readers require 'thread' bookstore = Queue.new writers = 4 readers = 5 writers.times do |w| Thread.new { 5.times { |x| bookstore.put("new book "+x.to_s+" by "+w) sleep 1+rand(5) } } end readers.times do Thread.new { 4.times { puts bookstore.pop } } end > > The Concurrency category on Wikipedia should give me plenty to read, > or at least know what to look for at the bookstore... > http://en.wikipedia.org/wiki/Category:Concurrency > I'm not sure what's the most popular book about algorithmics in you country - but try spending some money or go to library ^^ > Thanks again, > Erwin -- Marcin Raczkowski --- Friends teach what you should know Enemies Teach what you have to know