Version française
Home     About     Download     Resources     Contact us    
Browse thread
Does LablTk have a future?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Re: Feeding the OCaml GUI troll
On Thu, 2005-09-01 at 15:28 +0200, David MENTRE wrote:
> Hello,
> 
> 2005/9/1, skaller <skaller@users.sourceforge.net>:
> > I am. My idea is this: GET RID OF CALLBACKS.
> > The idea is to use (user space) threads instead.
> 
> The main issue with threads is that as soon as you want to share
> state/data between threads, it becomes a mess. 

Ah .. but read again: *user space* threads. Such as those
generated by Felix. They're C++, but a control inverter
for Ocaml shouldn't be too hard.

> The callback and main event handler scheme as the advantage of
> simplicity: your program does only one thing at a time.

Same as user space threads.

In Felix, something like this happens:

class f: public continuation {

f(caller, args) { 
	_caller = caller; 
	arg = args;
}

continuation *resume() {

	//read event
	switch (pc) { 
	...
		read_flag = true; 
		pe = &event; // where to put the event
		pc = 99;
		return this;
	case 99:
		
	// call subroutine(x)
		pc = 100;
		return new subroutine(this,x);
	case 100:
	...

	// return
		return _caller;

}
};


The driver loop is (crudely):

	while(p){
		p=p->resume();
		if(p->read_flag == true){
			p->pe = next_event();
			p->read_flag = false;
		}
	}

for a single thread. There's nothing here that can't
be done with an Ocaml class instead of a C++ one.

Probably, even with camlp4. The main problem is that
you can only yield when the machine stack is empty,
which means you HAVE to use continuations everywhere
you might want to read an event/yield.

MLton threads do this much better than Felix: they
use an MLton stack, not the machine stack,
and the MLton stack is kept linear using the
GC's compactor so it grows and shrinks *without*
losing linearity .. I wish I could do that in Felix.


-- 
John Skaller <skaller at users dot sourceforge dot net>