[Haskell-cafe] Re: all threads are blocked by recvFrom

Adam Langley agl at imperialviolet.org
Fri Mar 14 10:57:20 EDT 2008

On Fri, Mar 14, 2008 at 7:43 AM, Vitaliy Akimov
<vitaliy.akimov at gmail.com> wrote:
> Rebuilding of the network package with changed safety helped but I
>  don't think this is the solution. BTW accept is declared as safe. What
>  is the reason of declaring recvFrom as unsafe?  I think this breaks
>  highly required feature. Apparently it's impossible to make concurrent
>  server for non connection based protocols.

I assume that you're binding the libc function directly here:

In that case, you need to have the RTS manage sleeping your thread for
you. You should make the socket non-blocking and handle the EAGAIN and
EWOULDBLOCK cases by calling threadWaitRead[1] to block the current
Haskell thread only, until the fd is readable. Note that
threadWaitRead is GHC only.

If you download the source to network-bytestring[2], you can see a
very similar pattern in the code for send and recv in there.

Alternatively, you can use the functions in Network.Socket, which
should work fine.

[1] http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#v%3AthreadWaitRead
[2] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/network-bytestring-

Adam Langley agl at imperialviolet.org http://www.imperialviolet.org

More information about the Haskell-Cafe mailing list