apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lucian Adrian Grijincu" <lucian.griji...@gmail.com>
Subject Proper thread termination management
Date Tue, 11 Dec 2007 19:28:47 GMT
a project I'm working on needs to create & destroy threads in a manner
that I is not under my control. I only supply it the thread creation
and termination routines.

If the main thread exits, it runs apr_terminate() and kills every
pool, including the thread pools (even if the threads are detachable).

To protect myself from SIGSEGVs I record each apr_thread_t* created
and join them all before finishing execution.

	create_thread
		apr_thread_create(&thd)
		list_add_joinable_thread(thd)

	before apr_terminate() I run something like this:
		foreach thd in joinable_thd_list do:
			apr_thread_join(&status, thd)

The list can grow much if the program runs for a long time and many
threads get created (and I end up holding many HANDLES/pthread_ts)

Now this could be fixed by creating another thread that polls on the
list and joins threads as soon as they are added to the list, but I
was wondering if any of you have tackled a similar problem and found a
better solution.


-- 
Lucian

Mime
View raw message