[Haskell-cafe] threading question for ghc 7.0.2

Oliver Mueller oliver.mueller at gmail.com
Wed Mar 23 11:47:10 CET 2011


hello,
i'm a bit lost here so i hope s.o. can help me here:
seems i have a problem in my code when compiled with ghc-7.0.2:

what i try to do:
serverside:
-listen on a socket and reply to requests
client-side:
-send a request to that server
-wait for a response (with a timeout)

any ideas on how i can make this work again without using the -threaded flag?
is there is a better way for what i'm trying to achieve?
many thanks,
oliver

the simplified code is available at https://gist.github.com/882770
explanation:
the code forks of a lightweight thread (not an OS thread) that will
listen for incoming responses.
the main thread will go on to push out a message and then wait for the
receiver thread to finish.

i used to compile my application with the -threaded option but ran
into some obscure FFI problems after upgrading from ghc-6.12.3 to
ghc-7.0.2. so i tried to remove the -threaded option.
but now the message does not get pushed out until the receiver-thread
has finished.
what is strange to me is that this worked without problems on 6.12.3
but not on 7.0.2.
also the behavior is a little different on mac os X with 7.0.2: here i
get a "resource vanished (Connection reset by peer)"

see the output of the program below ([S] marks output from the main
thread, [R] from the receiver thread)

compiled on ghc-7.0.2/ubuntu 64bit, without -threaded

"running all things..."
   [R]listening for response...
   [R]wait for data with timeout:2000 ms
.........................................................................................................................................................................................................
   [R]no message available
[S]pushing out the message
[S]sending --> "\EOT\ETX"
"[S]going on..."
Nothing


compiled on ghc-7.0.2/ubuntu 64bit, using -threaded

"running all things..."
[S]pushing out the message
   [R]listening for response...
[S]sending --> "\EOT\ETX"
   [R]wait for data with timeout:2000 ms
"[S]going on..."

..................................................Just "\ETX\EOT"


and...also very strange: when i introduce a putStrLn in the main
thread (not a print !) it will work again...only a lot
(see code snipped line38: putStrLn "[S]hickup"

"running all things..."
[S]hickup
   [R]listening for response...
[S]pushing out the message
[S]sending --> "\EOT\ETX"
   [R]wait for data with timeout:2000 ms
"[S]going on..."
..................................................Just "\ETX\EOT"



More information about the Haskell-Cafe mailing list