maybe_resize should return ENOMEM when reallocation fails
make pthread_mutex_init reentrant