MacOS Thread Stack Size

figured I’d share this for any other plugin developers that may be hitting their heads against their desks as Rack crashes when creating threads inside of plugins:

be very careful of your thread stack size, or Rack will crash if you attempt to do something too large.

in my case, I had the audacity to move a bunch of FFT work into a thread, and any FFT calculations crossing the 64k memory line would crash immediately (but not when used outside of the thread).

default thread stack size is 524288, and you need at least 4x that for any FFT work using PFFFT (the FFT implementation that Rack provides) that goes above 65536.

learn from my frustration, and crank your stack size up to at least 100x what you’d realistically expect you need, PFFFT is a hungry hungry beast.

  pthread_attr_t thread_attr;
  pthread_attr_init(&thread_attr);
  pthread_attr_setstacksize(&thread_attr, 262144 * 100);
  pthread_t thread_id;
  pthread_create(&thread_id, &thread_attr, yourThread, NULL);
2 Likes

One could argue that it’s not great to allocate huge buffers on the stack. In this case it would be much easier, and probably more efficient, to allocate the FFT frames on your module, and hold onto the buffers for the lifetime of the module. That’s what our Colors modules does. It uses FFTs on a background thread to generate frames of colored noise.

Yeah allocate a work buffer and hand that to pffft, don’t use NULL, which makes the implementation use alloca().