summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2023-04-25 14:24:39 +0200
committerVladislav Vaintroub <wlad@mariadb.com>2023-04-25 14:26:55 +0200
commit2403eedb27c2dd3c55c4ca479069f9ee91dc3366 (patch)
tree46ee7217f7cb84a49caa4ab19873f51980de2400
parent3eaab28a875906c4cf8c9b1173ca2b2ad0bce513 (diff)
downloadmariadb-git-bb-10.6-wlad-tpool.tar.gz
MDEV-31095 tpool - do not create new worker, if thread creation is pending.bb-10.6-wlad-tpool
Use an std::atomic_flag to track thread creation in progress. This is mainly a cleanup, the effect of this change was not measureable in my tests.
-rw-r--r--tpool/tpool_generic.cc6
1 files changed, 5 insertions, 1 deletions
diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc
index c2d3f172817..fd97b4464af 100644
--- a/tpool/tpool_generic.cc
+++ b/tpool/tpool_generic.cc
@@ -278,6 +278,7 @@ class thread_pool_generic : public thread_pool
/* maintenance related statistics (see maintenance()) */
size_t m_last_thread_count;
unsigned long long m_last_activity;
+ std::atomic_flag m_thread_creation_pending= ATOMIC_FLAG_INIT;
void worker_main(worker_data *thread_data);
void worker_end(worker_data* thread_data);
@@ -575,6 +576,7 @@ void thread_pool_generic::worker_main(worker_data *thread_var)
m_worker_init_callback();
tls_worker_data = thread_var;
+ m_thread_creation_pending.clear();
while (get_task(thread_var, &task) && task)
{
@@ -720,11 +722,13 @@ static int throttling_interval_ms(size_t n_threads,size_t concurrency)
/* Create a new worker.*/
bool thread_pool_generic::add_thread()
{
+ if (m_thread_creation_pending.test_and_set())
+ return false;
+
size_t n_threads = thread_count();
if (n_threads >= m_max_threads)
return false;
-
if (n_threads >= m_min_threads)
{
auto now = std::chrono::system_clock::now();