From: Michael Neumann Date: 2001-11-30T08:28:15+09:00 Subject: [ruby-talk:26997] Re: Can someone explain TupleSpaces? Phil Tomson wrote: > I looked at the examples that came with drb, but I'm still not quite > grok'ing TupleSpaces. > > First of all, what is the Tuple? It seems to be a list of three items > (though I've seen more in some of the lists) - is it a way of calling a > method on a remote object by passing in an array of items with the first > element being the name of the method? (that's the theory I came up with > after looking at the examples - but I could be way off). Tuples come from mathematics. Unlike lists they have a predefined length. For example (1,2,3) is a 3-tuple, (1,"string",:3,4) a quadruple etc. A TupleSpace is a place where you can store arbitrary tuples. Two operations are defined on it: - put a tuple into the TupleSpace - get/remove a tuple (poss. specified by a pattern) from the TupleSpace Both operations are performed atomic (thread-safe). Suppose you have a server thread A and a client thread B. Thread A calls the "get" method accepting tuples matching ("add",_,_) where _ is a placeholder for any value. Method "get" waits until a matching tuple appears in the TupleSpace. The client thread B now wants to add two numbers. Therefore it puts a tuple ("add",2,3) into the TupleSpace. After that it waits for a tuple matching ("result",_). Now thread A returns from method "get", because a matching tuple ("add",2,3) exists, and removes this tuple. In response it puts a tuple ("result", 5) back into the TupleSpace. Thread B gets now active again and removes the tuple ("result",5) from the TupleSpace. > I guess I'm looking for the 50000ft view of TupleSpace... and can someone > tell me why I would use them? With this architecture you can very easy communicate and synchronize between different threads or processes. Regards, Michael -- Michael Neumann merlin.zwo InfoDesign GmbH http://www.merlin-zwo.de