From b0c8f04a531ca29a0256ab633dac09e55e1c83ba Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 16 Jun 2020 19:51:06 +0200 Subject: [PATCH] Updated the sleep stuff --- server/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/main.cpp b/server/main.cpp index 4c88bc5..81052b8 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -454,18 +454,21 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_ } } - int result, attempt{0}; + int result, attempt{0}, sleep{5}; while((result = original_pthread_create(thread, attr, start_routine, arg)) != 0 && errno == EAGAIN) { - if(attempt > 10) { - std::cerr << "[CRITICAL] pthread_create(...) cause EAGAIN for the last 10 attempts! Aborting application execution!" << std::endl; + if(attempt > 50) { + std::cerr << "[CRITICAL] pthread_create(...) cause EAGAIN for the last 50 attempts! Aborting application execution!" << std::endl; std::abort(); } else if(attempt > 5) { /* let some other threads do work */ pthread_yield(); } - std::cerr << "[CRITICAL] pthread_create(...) cause EAGAIN! Trying again in 5usec (Attempt: " << attempt << ")" << std::endl; - usleep(5); + + std::string message{"[CRITICAL] pthread_create(...) cause EAGAIN! Trying again in " + std::to_string(sleep) + "usec (Attempt: " + std::to_string(attempt) + ")"}; + std::cerr << message << std::endl; + usleep(sleep); attempt++; + sleep = (int) (sleep * 1.25); } return result; } \ No newline at end of file