[Yhc] Re: some initial questions

Tom Shackell shackell at cs.york.ac.uk
Thu Mar 9 17:16:41 EST 2006


> AFAIK, the context switch can only happen at "safe" moments, namely at a
> NEEDHEAP (or NEEDSTACK?) instruction.  Ordinary heap allocation is
> unchecked for overflow, so if there were arbitrary context switches, a
> thread could check there is enough space available with a NEEDHEAP, be
> switched out, then resume when the heap has been exhausted by another
> thread: crash bang.  Thus, the atomic unit of thread work must be
> exactly the sequence of instructions bounded by NEEDHEAP checks.

Indeed this is exactly right. The runtime only bothers to check whether 
to reschedule just before executing a NEEDHEAP.

NEEDSTACK was removed. It seemed easier to have the FInfo store the 
maximum stack usage and do the stack check on EVAL.

> At the moment, I'm pretty sure yhc does not implement foreign import
> wrapper.  (That one is on my todo list for nhc98 as well.)  But the
> point stands, even with foreign export.  Does the exported Haskell
> function get run in the separate OS thread (causes heap-locking issues)?
> Or will it be added back into the internal thread pool?

Again, exactly right, it doesn't do callbacks yet. Given the choice to 
avoid heap locks my inclination would be to get the OS thread to ask the 
main thread "Please run this Haskell code and wake me up when you're done".

Cheers :-)

Tom


More information about the Yhc mailing list