Waiting on Sockets or File Descriptors
wolfgang.thaller at gmx.net
Wed Feb 2 11:41:06 EST 2005
> So I guess I can't really use them in code that's supposed
> to be portable among different platforms?
> Maybe 'forkOS' combined with calling poll() through FFI
> really is the best solution? I seem to recall reading
> somewhere that the threaded RTS was more efficient for these
> applications anyway?
Two minor points:
a) poll() is not supported on Mac OS X and (at least some popular
versions of) BSD.
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,
and you only need forkOS if the actual identity of the OS thread
matters (i.e. when using thread-local state, OpenGL, some GUI
Apart from that, my guess is that it would be fairly efficient with the
The only inefficiency would be that if you're doing regular IO to
"slow" file handles at the same time, you'd get one (OS) thread in
GHC's libraries calling select() for the regular fds, plus a separate
(OS) thread running your call to select()/poll(). I'm not sure if
cleaning this up would be worth the effort - you get at least two OS
More information about the Glasgow-haskell-users