[Haskell-cafe] Threads talking back to parent

Sebastian Sylvan sebastian.sylvan at gmail.com
Mon Oct 31 16:27:48 EST 2005


On 10/31/05, Joel Reymont <joelr1 at gmail.com> wrote:
> Folks,
>
> I'm launching thousands of threads that send and receive commands. I
> would like the launching thread to keep a log of all the commands
> sent and received, in proper order.
>
> This would mean that each time a command is sent and received in the
> child thread it would need to be sent back to parent who would log
> the command on a first-come first-serve basis.
>
> How would I implement this in Haskell?
>

How about using a Chan?

http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-Chan.html

Send the Chan to all of the forked off processesses (so they take a
Chan as an argument). Whenever they need to send something back to the
server they write it to the Chan.
The main thread can then just read off the Chan and log it.



/S

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list