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

Vitaliy Akimov vitaliy.akimov at gmail.com
Mon Mar 17 05:29:01 EDT 2008


Hi Adam, sorry for late answer. Here is my example [1], but yours
doesn't work on my PC too. And it's strange it works on yours.
According to documentation for Control.Concurrent module [2] every
other thread should be blocked.
> With the -threaded option, only foreign calls with the unsafe attribute will block all other threads.
And after changing in the network package FFI declaration for
c_recvfrom from unsafe to safe both examples start working.
There are two solutions I see now. The first is to copy-paste
definitions from the network package to mine with changing "unsafe" to
"safe" for FFI declaration. The second is to use unblocking sockets.
This by the way will help to get rid of hack-like solution of stopping
server by closing listening socket, but it will get more effort.


[1] http://hpaste.org/6426
[2] http://haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#4

2008/3/14, Adam Langley <agl at imperialviolet.org>:
> On Fri, Mar 14, 2008 at 8:51 AM, Vitaliy Akimov
>
> <vitaliy.akimov at gmail.com> wrote:
>
> > > I assume that you're binding the libc function directly here:
>  >
>  >  I'm using Network.Socket. Sory if it's not clear from my previous posts.
>
>
> Then everything should Just Work(tm). You might need to paste in code
>  in order to figure out why this wouldn't be so.
>
>  See [1] for an example which works for me. It starts a thread which
>  prints "working..." once a second and, in another thread, listens for
>  UDP packets on port 4112. I can use `nc -u 127.0.0.1 4112` to get
>  this:
>  "working..."
>  "working..."
>  ("testing\n",8,127.0.0.1:36179)
>  "working..."
>  "working..."
>  ("testing two\n",12,127.0.0.1:36179)
>  "working..."
>
>
>
>  [1] http://hpaste.org/6362
>
>
>  --
>  Adam Langley agl at imperialviolet.org http://www.imperialviolet.org
>


More information about the Haskell-Cafe mailing list