summaryrefslogtreecommitdiffstats
path: root/source3/lib/pthreadpool/pthreadpool.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-08-21 19:55:06 +0000
committerJeremy Allison <jra@samba.org>2014-08-23 00:24:18 +0200
commit1c4284c7395f23cefa61a407db74cf5067aee2aa (patch)
tree3c8f210248558e0767eea97fbc70265326c2d7fe /source3/lib/pthreadpool/pthreadpool.c
parent4288c5496bcfa530066d5e8e4927472715b71465 (diff)
downloadsamba-1c4284c7395f23cefa61a407db74cf5067aee2aa.tar.gz
samba-1c4284c7395f23cefa61a407db74cf5067aee2aa.tar.xz
samba-1c4284c7395f23cefa61a407db74cf5067aee2aa.zip
pthreadpool: Slightly serialize jobs
Using the new msg_source program with 1.500 instances against a single msg_sink I found the msg_source process to spawn two worker threads for synchronously sending the data towards the receiving socket. This should not happen: Per destination node we only create one queue. We strictly only add pthreadpool jobs one after the other, so a single helper thread should be perfectly sufficient. It turned out that under heavy overload the main sending thread was scheduled before the thread that just had finished its send() job. So the helper thread was not able to increment the pool->num_idle variable indicating that we don't have to create a new thread when the new job is added. This patch moves the signalling write under the mutex. This means that indicating readiness via the pipe and the pool->num_idle variable happen both under the same mutex lock and thus are atomic. No superfluous threads anymore. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/lib/pthreadpool/pthreadpool.c')
-rw-r--r--source3/lib/pthreadpool/pthreadpool.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/source3/lib/pthreadpool/pthreadpool.c b/source3/lib/pthreadpool/pthreadpool.c
index 4436ab3289..d683578617 100644
--- a/source3/lib/pthreadpool/pthreadpool.c
+++ b/source3/lib/pthreadpool/pthreadpool.c
@@ -536,11 +536,11 @@ static void *pthreadpool_server(void *arg)
assert(res == 0);
job.fn(job.private_data);
- written = write(sig_pipe, &job.id, sizeof(job.id));
res = pthread_mutex_lock(&pool->mutex);
assert(res == 0);
+ written = write(sig_pipe, &job.id, sizeof(job.id));
if (written != sizeof(int)) {
pthreadpool_server_exit(pool);
pthread_mutex_unlock(&pool->mutex);