RE: [Haskell-cafe] Unbound threads and FFI

On 14 December 2005 15:34, Joel Reymont wrote:
On Dec 14, 2005, at 3:21 PM, Simon Marlow wrote:
this only happens in the -threaded RTS, in the non-threaded RTS a FFI call will block all the other Haskell threads.
Just to be absolutely sure... Does the above apply to safe _and_ unsafe FFI?
I have been using the non-threaded runtime with unsafe FFI calls (OpenSSL, Zlib) and I do not believe my runtime was being blocked. Maybe I just didn't notice it, though.
Maybe this little table will help: Do other Haskell threads get blocked during an FFI call? | safe unsafe --------------+---------------- -threaded | NO YES no -threaded | YES YES Cheers, Simon

Hello Simon, Wednesday, December 14, 2005, 7:39:43 PM, you wrote: SM> Do other Haskell threads get blocked during an FFI call? SM> | safe unsafe SM> --------------+---------------- SM> -threaded | NO YES SM> no -threaded | YES YES there is also `threadsafe` specifier. i don't understand from the docs what it exactly means? ghc commentary says: To signal that you want an external call to be serviced by a separate OS thread, you have to add the attribute threadsafe to a foreign import declaration, i.e., foreign import "bigComp" threadsafe largeComputation :: Int -> IO () The distinction between 'safe' and thread-safe C calls is made so that we may call external functions that aren't re-entrant but may cause a GC to occur. The threadsafe attribute subsumes safe. -- Best regards, Bulat mailto:bulatz@HotPOP.com

On Wed, Dec 14, 2005 at 04:39:43PM -0000, Simon Marlow wrote:
Do other Haskell threads get blocked during an FFI call?
| safe unsafe --------------+---------------- -threaded | NO YES no -threaded | YES YES
this is part of the reason I'd like to see a separate 'blockable' specifier allowed on foreign imports. so that one can write portable thread-safe libraries. right now, if one want's to call something like gethostbyname(3), they must call it with 'safe' so every implementation has to pay the price of a safe call even though it is only there so ghc won't block. (or #ifdefs, which are anoying) if blockable were separate then it can be declared 'blockable unsafe' and ghc will interpret that as 'safe' while non-threaded implementations will interpret it as 'unsafe' and everyone is happy. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (3)
-
Bulat Ziganshin
-
John Meacham
-
Simon Marlow