I am developing a non preemptive multi threading library in linux (in C) . The requirement is to use getcontext
setcontext
etc to create new threads and manage them. The library is working as expected for normal conditions.
I use malloc for each thread object(MyThread) and i exit gracefully by printing a message "malloc failed"
if malloc returns NULL
.To test extreme conditions, i ran a recursive fibonacci function which creates child threads to calculate sub calculations.I ran fib
with increasing numbers and reached the limit at fib 26
.
But malloc is not complaining. It is the linux system which reaches OOM
and kills the process.
Question: Why is malloc
returning success ( a new pointer ) while the system finds itself out of space?