diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2011-12-18 23:03:35 +0100 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2011-12-18 23:03:35 +0100 |
commit | 2e4bde4c0febf1282639ce2f13e24c707e1f45b0 (patch) | |
tree | cb9a25e0fba4d34c29dd3a23694677d41ec59ca4 /sql/threadpool_unix.cc | |
parent | a5a22e9f641623886ec7c051e7ae40eadad0b023 (diff) | |
download | mariadb-git-2e4bde4c0febf1282639ce2f13e24c707e1f45b0.tar.gz |
Fix pool_of_threads test case
Diffstat (limited to 'sql/threadpool_unix.cc')
-rw-r--r-- | sql/threadpool_unix.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc index f0d7d5f33be..a8ceb250e5c 100644 --- a/sql/threadpool_unix.cc +++ b/sql/threadpool_unix.cc @@ -624,14 +624,22 @@ static pool_event_t * listener(worker_thread_t *current_thread, -/* Creates a new worker thread. thread_mutex must be held when calling this function */ +/* + Creates a new worker thread. + thread_mutex must be held when calling this function + + NOTE: in rare cases, the number of threads can exceed + threadpool_max_threads, because we need at least 2 threads + per group to prevent deadlocks (one listener + one worker) +*/ static int create_worker(thread_group_t *thread_group) { pthread_t thread_id; int err; DBUG_ENTER("create_worker"); - if (tp_stats.num_worker_threads >= (int)threadpool_max_threads) + if (tp_stats.num_worker_threads >= (int)threadpool_max_threads + && thread_group->thread_count >= 2) { DBUG_PRINT("info", ("Cannot create new thread (maximum allowed threads reached)")); @@ -667,6 +675,9 @@ static int wake_or_create_thread(thread_group_t *thread_group) if (thread_group->pending_thread_start_count > 0) DBUG_RETURN(-1); + if (thread_group->thread_count > thread_group->connection_count) + DBUG_RETURN(-1); + if (thread_group->thread_count < 4) { DBUG_RETURN(create_worker(thread_group)); |