[S3] Sleepy malloc

The malloc(3) function may fail, for instance if the OS has no free memory remaining. In this case, it may be possible that some other processes to free some memory after some time.

In our program, instead of reporting an error immediately if no free memory is available, we will wait some time to see if the OS has freed memory for us.

Sleepy malloc

Write the body of the function sleepy_malloc.

/* Wrapper to the malloc system call.
 * If malloc fails, sleep for 5 seconds, and then try again.
 * If malloc failed 10 times in a row, return NULL.
void *sleepy_malloc(size_t s) {


Author(s) Mathieu Xhonneux & Maxime Mawait
Deadline No deadline
Submission limit No limitation
Category Tags S3


Sign in