Please: change TASK_SLOTS_STEP to 384 (ltask.c:49) and check
again with N between 255 and 380. Tell me if the segfault is
gone.
The segfaults seem to start at N == TASK_SLOTS_STEP.
With TASK_SLOTS_STEP at 256, it works until N == 255, then segfaults. I
set it to 384 and the segfaults start when N == 384. For N at 381, 382,
383 it all work fine.
I tried setting TASK_SLOTS_STEP to 443, and the behaviour was what you
might expect: it worked up to 442 tasks and segfaulted from 443 and up.