Ashley Yakeley wrote:
| > timeOut :: Int -> IO a -> IO (Maybe a) : | Sounds rather unsafe. What happens to the IO action | after the specified time?
Good point. Actually, a function of the type:
timeOut :: Int -> a -> IO (Maybe a)
would suffice for my purposes, but I tried to be a bit more general when I posed my question.
It's only unsafe if your code isn't written to cope with asynchronous exceptions. Doing this in most cases just amounts to using combinators like Control.Exception.bracket to do the exception handling for you. In FFI code you have to be more careful, however. Cheers, Simon
In FFI code you have to be more careful [about killing threads], however.
It's clear there's a bunch of bad things could happen here - but not obvious what does happen. Does killing a thread that is calling a C function kill it immediately (i.e., before the call completes) or wait until the C function finishes? -- Alastair
participants (2)
-
Alastair Reid -
Simon Marlow