Eternal Gratitude for the help, it's working perfectly, I will consider the exceptions and other stuff now.

the code looks like this now


import System.IO
import Control.Concurrent
import Data.List 
import Control.Monad

main = do
          finished <- newEmptyMVar
          input <- newMVar  [1..30000]
          ia <- newEmptyMVar
          ib <- newEmptyMVar
          ic <- newEmptyMVar

          forkIO $ do x <- readMVar input
                      putMVar ia x
                      putMVar finished ()

          forkIO $ do a <- readMVar ia
                      putMVar ib ( sum a )
                      putMVar finished ()

          forkIO $ do a <- readMVar ia
                      putMVar ic ( reverse a )
                      putMVar finished ()

          b <- readMVar ib
          c <- readMVar ic
          writeFile "somaEprod.txt" (show b ++ "\n") 
          appendFile "somaEprod.txt" (show c)             
          replicateM_ 3 (takeMVar finished)




Valeu
Mauricio

On Sun, Jul 1, 2012 at 12:24 AM, Felipe Almeida Lessa <felipe.lessa@gmail.com> wrote:
Your application is exiting before your forkIOs get a chance to
execute.  Instead of

 forkIO $ do
   ...
 forkIO $ do
   ...
 forkIO $ do
   ...

use something like

 finished <- newEmptyMVar

 forkIO $ do
   ...
   putMVar finished ()

 forkIO $ do
   ...
   putMVar finished ()

 forkIO $ do
   ...
   putMVar finished ()

 replicateM_ 3 (takeMVar finished)

Doing so will avoid your program to exit until all threads have finished.

Note that the code above is extremely fragile: doesn't handle
exceptions, you have to manually specify the number of threads that
you opened, etc.  These are abstracted by some libraries on Hackage
that you may use later for Real World Code (TM).

Cheers, =)

--
Felipe.