From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-11-30T08:55:42+09:00 Subject: [ruby-talk:27002] Re: Can someone explain TupleSpaces? In article <20011130002401.A2889@michael.neumann.all>, Michael Neumann wrote: >Phil Tomson wrote: >> >> 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 > Thanks. It's starting to make sense. I almost get the feeling that a TupleSpace is sort of like some kind of super Hash where keys and values are interchangable only there can be multiple values and keys (well, it's probably a poor analogy. I think I'm starting to see the light, though.) Phil