Informações

Autores Mathieu Xhonneux & Maxime Mawait
Prazo de entrega Sem prazo
Limite de submissão No limitation
Category tags S3, Malloc, Level 2

Etiquetas

Entrar

[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 free some memory after some time and then we could use it again.

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. Use the function sleep(3).

/* 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) {