[clean-list] Process starting

Arjen van Weelden A.vanWeelden at cs.ru.nl
Thu Mar 9 11:27:35 MET 2006


Hernyák Zoltán wrote:
>>> So there is no way to start on separate threads?
>> Not using Object I/O as it is implemented at the moment.
> It is a really bad news.
> 
>> It still looks as if two separate programs, or a single program 
>> started twice, could solve your problem, in combination with a TCP/IP 
>> library.
> No, there is no way, because I have to implement a kind of STUB function
> in Clean, which sends its argument data to a port, and receives the result
> from another port. You cannot send and receive on the same process, because
> that would means a cycle with continuous checking the possibility of 
> sending
> or receiving. And this would means a strict evaulation of the result of 
> this
> STUB function, because this cycle could end only if all the result is 
> received.
> We simple cannot do that.

Using the existing TCP/IP implementation you could program a loop that 
checks for new incoming data, does a little computation, send the result 
back, and checks again for incoming data. If you can split large 
computations into small steps, you can compute a little between checking 
for new data. Unfortunately, you have do this kind of splitting and 
interleaving yourself. Any large computation can be split into many 
small steps but this can be a lot of work.

If you don't want to split the computation you need something like 
Haskell's getContents, which performs lazy I/O. It is possible to 
program something like that in Clean. One could define a function that 
returns a lazy list of inputs that only uses TCP/IP when you evaluate 
the next element in the list. Is that what you need?

>> Examples\chat\chat{Client|Server}.icl. This can easily be incorporated 
>> into the example containing newProcess that I sent you.
> So what this newProcess do anyway? Won't it start a process on a separate
> thread?

It DOES start a process on a separate thread, have you tried it yet? 
StartProcess starts a server that spawns new processes (that run in 
separate threads managed by the O/S) when you use newProcess. It even 
recycles processes that finished their work so that they can be reused 
without the overhead of starting a new O/S process.

Any communication between separately running processes has to be 
explicitly programmed (by you). You could use TCP/IP for that, by 
interleaving sends and receives. TCP/IP communication is buffered (up to 
a certain limit),  which means that two threads can run simultaneously 
until the buffer is empty or full. You have to be careful to use a 
protocol that supports the communication you want, while still allowing 
both processes to do other useful work and without deadlocking.

>  > (one more thing: don't use so many #!'s, they are hardly ever necessary)
> Yes, thanks, but my problem is a little bit complicated as my small 
> example shows that.
> I have to call a lot of external C functions, and must implement a real 
> sequence, which
> cannot be without #! :)
 >
 > Thank you for your answers,
 >

Usually, you do this by using environment passing (using the World or 
another state) and using # . It forces a sequence based on the data 
dependency of the state. This works better that (hoping to) force 
evaluation using #!, since its semantics are not well defined. If you're 
not careful, #! does not even enforce the evaluation that you 
want/expect! This is something I've observed from myself and from other 
Clean programmers. Maybe you're an expert and all this does not apply to 
you. It was just a suggestion to improve your Clean style.

regards,
	Arjen



More information about the clean-list mailing list