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
This commit is contained in:
Michael Ploujnikov 2009-11-25 17:43:22 -05:00
parent 8e3d4e7b7a
commit 07962b5314
4 changed files with 75 additions and 6 deletions

View file

@ -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");
// }
}
/*

View file

@ -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

View file

@ -8,17 +8,19 @@ PLANNED "cancel"
TEST "Acquire/Release test" basic-acquire-release <<END
err: start by initializing the threadpool
err: acquiring thread 1
err: allocated thread struct of size
err: acquiring thread 2
err: allocated thread struct of size
err: releasing thread 1
err: thread 1 has been released
err: releasing thread 2
err: thread 2 has been released
err: destroying threadpool
err: destroying individual pool #0
err: number of threads in the pool=1
err: deleting thread
err: destroying thread
err: destroying the pool mutex
err: pool mutex destroyed
@ -40,8 +42,41 @@ err: pool mutex destroyed
err: destroying individual pool #4
err: number of threads in the pool=1
err: deleting thread
err: destroying thread
err: destroying the pool mutex
err: pool mutex destroyed
END
TEST "Many Acquires/Releases test" many-acquire-release <<END
err: allocated thread struct of size
err: destroying threadpool
err: destroying individual pool #0
err: number of threads in the pool=1000
err: deleting thread
err: destroying the pool mutex
err: pool mutex destroyed
err: destroying individual pool #1
err: number of threads in the pool=1000
err: deleting thread
err: destroying the pool mutex
err: pool mutex destroyed
err: destroying individual pool #2
err: number of threads in the pool=1000
err: deleting thread
err: destroying the pool mutex
err: pool mutex destroyed
err: destroying individual pool #3
err: number of threads in the pool=1000
err: deleting thread
err: destroying the pool mutex
err: pool mutex destroyed
err: destroying individual pool #4
err: number of threads in the pool=1000
err: deleting thread
err: destroying the pool mutex
err: pool mutex destroyed
END

View file

@ -64,4 +64,32 @@ TEST ("basic-acquire-release")
lumiera_threadpool_destroy();
}
TEST ("many-acquire-release")
{
const int threads_per_pool_count = 1000;
lumiera_threadpool_init();
LumieraThread threads[threads_per_pool_count*LUMIERA_THREADCLASS_COUNT];
for (int kind = 0; kind < LUMIERA_THREADCLASS_COUNT; ++kind)
{
for (int i = 0; i < threads_per_pool_count; ++i)
{
threads[i+kind*threads_per_pool_count] =
lumiera_threadpool_acquire_thread(kind,
"test purpose",
NULL);
}
}
for (int i = 0; i < threads_per_pool_count*LUMIERA_THREADCLASS_COUNT; ++i)
{
lumiera_threadpool_release_thread(threads[i]);
}
lumiera_threadpool_destroy();
}
TESTS_END