Waiting on Sockets or File Descriptors

Simon Marlow simonmar at microsoft.com
Thu Feb 3 04:56:03 EST 2005

On 02 February 2005 19:48, Peter Simons wrote:

> Wolfgang Thaller writes:
>  > a) poll() is not supported on Mac OS X and (at least some
>  > popular versions of) BSD.
> Are you certain? Just tried "man poll" on one of the MacOS X
> machines the SourceForge compile farm offers, and that one
> had it: "Darwin ppc-osx1 5.5 Darwin Kernel Version 5.5".
>  > b) 'forkIO' in the threaded RTS would suffice in this
>  > case, as the poll() or select() system calls don't use
>  > any thread-local state. In the threaded RTS, "safe"
>  > foreign imports never affect other threads [...].
> That would be really good news! I assumed that GHC's runtime
> system used one thread for _all_ FFI invocations? (Unless
> you start new ones.) So I thought calling poll() would block
> all other FFI invocations until it returned?
> Or is that only for "unsafe" FFI calls?

When you compile your program with -threaded, "safe" FFI calls don't
block other threads, but "unsafe" calls still do.  Basically a "safe"
FFI call releases the lock on the RTS so other Haskell threads can
continue to run (and that at least partly explains why we have the
distinction: releasing and re-acquiring a lock is expensive).

> Do you have an URL for me where I can find out more about
> this, by any chance?

There's not much, but the -threaded option is documented here:


and the Control.Concurrent documentation explains what "bound" threads


More information about the Glasgow-haskell-users mailing list