[MLton-devel] calling SML from C; reentrance

Matthew Fluet fluet@cs.cornell.edu
Fri, 16 May 2003 17:31:28 -0400 (EDT)


> > In a "single threaded" main program, there will really only ever be
> > one stack of execution, just chained together through C functions.
>
> I'm not quite sure what you mean by "one stack of execution".  With
> your code, each C call causes a call to install, which creates a new
> SML thread with a new stack.

Well, what I meant was that the execution is still single-threaded.  In
reality, we have a stack of stacks -- in the sense that only one stack is
ever active at a time (and no switching to one of the other stacks) and we
leave one stack by returning to C only to return to SML on the next stack.

> How about the following, based on the idea of creating one thread per
> C call, but requiring only one call in total to
> Prim.setCallFromCHandler and requiring no thread creation when making
> additional calls to setCallFromCHandler.  It seems cleaner to me.
...

I don't object, although it's less intuitive for me to figure out what's
going on.  (Not hard, just not as immediately obvious why the
"real" handler will always launch the client handler.)

>
> Hmm.  It occurs to me that with this code may lead to a way execute on
> top of the existing SML stack that called the C function.  Maybe we
> need to add a primtive for executing a function call on top of a
> stack?

What are the advantages of executing the function on top of the current
stack?  I mean, once there are any thread primitives in the program, we're
pretty well hosed for some optimizations, so whether or not we can ensure
that only one stack exists at runtime won't make much of a difference.
Or, were you envisioning a primitive that wouldn't need to use threads to
execute the handler.




-------------------------------------------------------
This SF.net email is sponsored by: If flattening out C++ or Java
code to make your application fit in a relational database is painful, 
don't do it! Check out ObjectStore. Now part of Progress Software.
http://www.objectstore.net/sourceforge
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel