From: Andy Gimblett Date: 2006-04-22T00:34:39+09:00 Subject: Re: Synchronized object On Fri, Apr 21, 2006 at 11:47:56PM +0900, Kroeger, Simon (ext) wrote: > Dear ruby-talk, > > is there a nice, concise way to lock each and every method against > all other methods of an object? > > To elaborate: I want to make sure that only one method of a specific > object (not class) can run at a each point in time regardless of how > many threads are using this object. > > I would hope there is module i just have to include in my class > definition. If you want something like you get in Java with the "synchronized" keyword, that's a monitor, and the standard library includes (the not terribly well documented) monitor.rb: http://www.ruby-doc.org/stdlib/libdoc/monitor/rdoc/ (also http://en.wikipedia.org/wiki/Monitor_%28synchronization%29 ) Whether it's nice or concise I don't know - it's certainly not a "one-liner" way to achieve what you want but it might get you a long way along the road. If you use it, I'd personally be interested in how you got on. (Caveat: I haven't used this, I just saw "synchronized object" in your subject line, thought "monitor", and searched the web for "ruby monitor synchronization" which led me to this info.) Hope this helps, -Andy -- Andy Gimblett Computer Science Department University of Wales Swansea http://www.cs.swan.ac.uk/~csandy/