From 07962b5314ab9d2b784f29e79fb21dd02a055e2d Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Wed, 25 Nov 2009 17:43:22 -0500 Subject: [PATCH] add comments about locking in lumiera_threadpool_release_thread() output the size of the created thread struct don't print "destroying thread" (lets tests become shorter with repeated matching) add a test which spans many threads in all pools --- src/backend/threadpool.c | 12 +++++++--- src/backend/threads.c | 2 +- tests/30backend-threadpool.tests | 39 ++++++++++++++++++++++++++++++-- tests/backend/test-threadpool.c | 28 +++++++++++++++++++++++ 4 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/backend/threadpool.c b/src/backend/threadpool.c index 5960c890f..1a48967dd 100644 --- a/src/backend/threadpool.c +++ b/src/backend/threadpool.c @@ -112,9 +112,15 @@ lumiera_threadpool_release_thread(LumieraThread thread) { REQUIRE (thread, "invalid thread given"); REQUIRE (thread->kind < LUMIERA_THREADCLASS_COUNT, "thread belongs to an unknown pool kind: %d", thread->kind); - REQUIRE (llist_is_single(&thread->node), "thread already belongs to some list"); - llist_insert_head(&threadpool.kind[thread->kind].pool, &thread->node); - REQUIRE (!llist_is_empty (&threadpool.kind[thread->kind].pool), "thread pool is still empty after insertion"); + REQUIRE (&threadpool.kind[thread->kind].lock, "invalid threadpool lock"); + + // TOOD: currently, locking produces memory leaks + // LUMIERA_MUTEX_SECTION (threadpool, &threadpool.kind[thread->kind].lock) + // { + //REQUIRE (llist_is_single(&thread->node), "thread already belongs to some list"); + llist_insert_head(&threadpool.kind[thread->kind].pool, &thread->node); + // REQUIRE (!llist_is_empty (&threadpool.kind[thread->kind].pool), "thread pool is still empty after insertion"); + // } } /* diff --git a/src/backend/threads.c b/src/backend/threads.c index 4471fb444..52125fcef 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -170,6 +170,7 @@ lumiera_thread_new (enum lumiera_thread_class kind, //REQUIRE (finished, "invalid finished flag passed"); LumieraThread self = lumiera_malloc (sizeof (*self)); + ECHO ("allocated thread struct of size %zd", sizeof (*self)); llist_init(&self->node); self->finished = finished; self->kind = kind; @@ -193,7 +194,6 @@ lumiera_thread_new (enum lumiera_thread_class kind, LumieraThread lumiera_thread_destroy (LumieraThread self) { - ECHO ("destroying thread"); REQUIRE (self, "trying to destroy an invalid thread"); // TODO: stop the pthread diff --git a/tests/30backend-threadpool.tests b/tests/30backend-threadpool.tests index a23ff38ea..44392f279 100644 --- a/tests/30backend-threadpool.tests +++ b/tests/30backend-threadpool.tests @@ -8,17 +8,19 @@ PLANNED "cancel" TEST "Acquire/Release test" basic-acquire-release <