Phil,
It should work although I don't think I've ever actually tested it. At
the start of a callback the code calls PolyX86GetThreadData to get the
ML thread data including a reference to the ML stack. This is stored in
thread-local storage. If it is empty it assumes this is a new thread
and calls CreateNewTaskData to create new ML thread data and a new stack.
David
On 13/11/2022 23:37, Phil Clayton wrote:
I am wondering whether it is possible for a new thread to be created in
foreign code by some other library and for the new thread to call back
into ML. As the new thread would not be created by Poly/ML, presumably
it would not have its own ML stack and that sounds problematic, given
the description in the original paper [1]. On the other hand, perhaps
an ML stack is provided by the callback closure. I briefly looked at
the source code, and ended up at buildCallBack in X86ForeignCall.ML, but
I would need to understand the code generation to make sense of that.
Phil
1.Efficient Parallel Programming in Poly/ML and Isabelle/ML
...
Like every thread that runs ML code this new thread has both
an operating-system stack that it uses when running in the RTS or
in “foreign” code through the foreign-function interface (FFI) and
an ML stack that is used when running ML code. The ML stack is
an object within the ML heap and can be scanned and updated by
the garbage-collector.
...
Because all threads are created by calls to the RTS and all
interaction with the operating system is through it the RTS is able
to maintain a table of threads and their current state. Knowing the
state of all threads is particularly important for garbage collection.
...
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml
_______________________________________________
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml