
On 20 January 2005 11:30, Keean Schupke wrote:
Simon Marlow wrote:
Yes, except that you forgot that not all foreign calls can run
concurrently with Haskell code. Only the "safe" ones can.
Okay, now I understand what is going on. Why is there extra overhead for a 'safe' call?
A safe call must - save its state on the Haskell stack - save its thread state object on a queue, so GC can find it - tidy up the stack so GC can take place - release the RTS lock - possibly start a new OS thread if the pool is empty of these, releasing the RTS lock is probably the most expensive. Also, if another OS thread gets scheduled before the call returns, we have an expensive context switch on return. In contrast, an unsafe call is just an inline C call. Cheers, Simon