GHC exited with error -24

I was trying to compile something the other day, and after fighting with stack running out of memory when run with multithreading turned on (on a box with 4GB of ram??), I eventually got to a point where cabal, or GHC, or something else in the stack was exiting with error code -24.