Reproducing an issue I have seen when using multi-threaded C FFI with Haskell
Haskell C
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Makefile
README
T.hs
test.c

README

This test reproduces an issue with C FFI I have seen - the number of worker threads start going up if number of C FFI threads is set beyond a threshold. On my test machine, the threshold seems to be 6. I am using ghc 7.4.1.

To reproduce the issue:

- Set nThreads in T.hs (line 51) to a high number, for example, 10. That will kick off nThreads threads in C FFI

- Compile the code (need gcc too): make

- Start the test: ./T -N3 +RTS -s 

- You will see messages being printed on console. After a few "Processed data" messages have been printed (i.e., a few timer events have executed), kill the process by sending ctrl-c. RTS will show output, listing number of worker threads. They should be higher than 12. The more iterations there are, the more worker threads there should be.

I can reproduce the segmentation fault using this simple test case if I set nThreads to a high number like 30, on Mac. On Linux, segmentation fault happens but not very often. Core dump on Mac shows output similar to below:

#0  0x00007fff9321fbca in __psynch_cvwait ()

It seems to happen in mvar callback.