On Tue, 2007-04-17 at 08:35 +1000, skaller wrote: > Felix supports a radical new programming paradigm -- programming > with circuits.
Ok, here are some more comments and ideas. In the model: spawn_fthread { Sin (xin, yout); }; shows that a chip is different from a procedure. Here Sin is a *design* for a chip, but it is actually the fthread which is the chip: in other words, this is a dynamic instantiation of a template which not only creates an actual chip .. it also plugs it into the circuit by connecting particular wires to it. The arguments are wires -- the procedure parameters are (models of) 'pins' or 'ports' to connect the wires to. //// This code: write (bout, b); write (nout, n); var &y0 : double <- read yin; in Cauchy illustrates one of the problems. We're actually connecting here to a Newton chip which does this: var &b : double <- read bin; var &n : int <- read nin; It's vital that reads and writes be correctly ordered, or the circuit deadlocks. There is a way around this: have only one input and one output, and *multiplex* the data. This is done using a union: union Newt = | B of double | N of double; Now it doesn't matter what order you write the b and n values into the wire, the read can just decode the value and take action accordingly. But now there is a new problem: you have to be careful to write exactly one B and one N: the order doesn't matter but you have to write one of each. This can be fixed by using defaults, writing any number of B and N codes, and adding a new code DONE to terminate the input stream. Another technique is to use buffering .. a buffering chip is called a latch. [Exercise for reader: design a generic latch .. :] /// You should note that the way the chips work is by message passing. However only ONE message can be passed at once across the whole circuit. This is like a real circuit with the properties: (a) all the chips are clocked (b) all I/O is tristated except one pair of chips so that only one signal is passed at once. The channels are what ensures that there is a single thread of control, and it moves along with the message. The selected pair of chips -- the ones that can communicate -- are said to be active, and in particular, the WIRE connecting them is active. As the clock ticks, the active wire changes. The trace of active wires over time is called the thread of control. /// Can more than one message be passed at once with this model? YES. Just use spawn_pthread and pchannels .. but don't forget that if you have any shared memory communication you have to mutex accesses. Pre-emptive model is more likely to work than the fibrated one .. so why use fibres? The answer is simple: PERFORMANCE Fibres are FAST and have low memory overhead. Of course ideally you use a mix: pthreads scale to multiple processors, fthreads don't. With suitable messing about .. we can introduce another kind of channel. That's the interprocess channel .. which typically uses TCP/IP and works over the Internet. [That system already exists .. it's called Erlang :] Oh .. of course channels are another kind of stream [but not a byte stream, since they're typed] -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language