I\'m writing a program where a large number of agents listen for events and react on them. Since Control.Concurrent.Chan.dupChan is deprecated I decided to use TCha
Adding to what Neil said, your code also has a space leak (noticeable with smaller n):
After fixing the obvious tuple build-up issue by making tuples strict, I was left with the following profile:
What's happening here, I think, is that the main thread is writing data to the shared TChan faster than the worker threads can read it (TChan, like Chan, is unbounded). So the worker threads spend most of their time reexecuting their respective STM transactions, while the main thread is busy stuffing even more data into the channel; this explains why your program hangs.