This neatly brings us to the next point: is there a way to have the application know that stack memory is in danger of being, or rather, has been, overflowed? Indeed: stack guards. Guard memory is a region of one or more virtual memory pages that has been deliberately placed, and with appropriate permissions, to ensure that any attempt to access that memory results in failure (or a warning of some sort; for example, a signal handler for SIGSEGV could provide just such a semantic - with the caveat that once we've received the SIGSEGV, we are in an undefined state and must terminate; but at least we'll know and can fix the stack size!):
#include <pthread.h>int pthread_attr_setguardsize(pthread_attr_t *attr, size_t guardsize);