From 2a77e3d16dd3abdab49b7b178a31d34ac8d1c444 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 19 Dec 2018 12:55:07 +0000 Subject: Abort on out of threads. --- vespamalloc/src/vespamalloc/malloc/malloc.h | 2 +- vespamalloc/src/vespamalloc/malloc/threadproxy.cpp | 27 ++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'vespamalloc/src') diff --git a/vespamalloc/src/vespamalloc/malloc/malloc.h b/vespamalloc/src/vespamalloc/malloc/malloc.h index 9ce62e4f00d..b3131ac5cbb 100644 --- a/vespamalloc/src/vespamalloc/malloc/malloc.h +++ b/vespamalloc/src/vespamalloc/malloc/malloc.h @@ -23,7 +23,7 @@ public: void setReturnAddressStop(const void * returnAddressStop) override { MemBlockPtrT::Stack::setStopAddress(returnAddressStop); } - virtual size_t getMaxNumThreads() const override { return _threadList.getMaxNumThreads(); } + size_t getMaxNumThreads() const override { return _threadList.getMaxNumThreads(); } void *malloc(size_t sz); void *realloc(void *oldPtr, size_t sz); diff --git a/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp b/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp index c1b8f05ee98..fd3a1748b92 100644 --- a/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp +++ b/vespamalloc/src/vespamalloc/malloc/threadproxy.cpp @@ -68,15 +68,17 @@ void * mallocThreadProxy (void * arg) } -extern "C" VESPA_DLL_EXPORT int local_pthread_create (pthread_t *thread, - const pthread_attr_t *attrOrg, - void * (*start_routine) (void *), - void * arg) __asm__("pthread_create"); - -VESPA_DLL_EXPORT int local_pthread_create (pthread_t *thread, - const pthread_attr_t *attrOrg, - void * (*start_routine) (void *), - void * arg) +extern "C" VESPA_DLL_EXPORT int +local_pthread_create (pthread_t *thread, + const pthread_attr_t *attrOrg, + void * (*start_routine) (void *), + void * arg) __asm__("pthread_create"); + +VESPA_DLL_EXPORT int +local_pthread_create (pthread_t *thread, + const pthread_attr_t *attrOrg, + void * (*start_routine) (void *), + void * arg) { size_t numThreads = _G_threadCount; while ((numThreads < vespamalloc::_G_myMemP->getMaxNumThreads()) @@ -84,7 +86,14 @@ VESPA_DLL_EXPORT int local_pthread_create (pthread_t *thread, { } if (numThreads >= vespamalloc::_G_myMemP->getMaxNumThreads()) { +#if 1 + // Just abort when max threads are reached. + // Future option is to make the behaviour optional. + fprintf (stderr, "All %ld threads are active! Aborting so you can start again.\n", numThreads); + abort(); +#else return EAGAIN; +#endif } // A pointer to the library version of pthread_create. static pthread_create_function real_pthread_create = NULL; -- cgit v1.2.3