thread pool exiting problem

hi, i was wondering if there is anybody who knows how to cleanly shutdown a
thread pool. seems as if i try to pthread_exit, the thread_pool_manager
thingy keeps creating new ones to ensure the low-water mark is met. i am a
little stumped.

reuben

reubix.com (mavericks surf mofo)

reuben walraven wrote:

hi, i was wondering if there is anybody who knows how to cleanly shutdown
a
thread pool. seems as if i try to pthread_exit, the thread_pool_manager
thingy keeps creating new ones to ensure the low-water mark is met. i am
a little stumped.

reuben

alright, so i have found a way and it works.

i basicly have to keep a table, list, or tree of each thread that the
thread pool creates. so

in context_allocation function

  • add me (pthread_self) into the list

in context_free function

  • delete_me (pthread_self) from the list.

now if the main thread (not part of the thread pool) or some other thread
wants to cancel the thread pool, it will have to traverse the list and
pthread_cancel (thread_id from table entry) each one. QNX should have a
clean thread_pool_stop though. I mean they have a thread_pool_start.

thanks

reuben

\

reubix.com (mavericks surf mofo)

reuben walraven <reuben@reubix.com> wrote:

reuben walraven wrote:

hi, i was wondering if there is anybody who knows how to cleanly shutdown
a
thread pool. seems as if i try to pthread_exit, the thread_pool_manager
thingy keeps creating new ones to ensure the low-water mark is met. i am
a little stumped.

reuben

alright, so i have found a way and it works.

i basicly have to keep a table, list, or tree of each thread that the
thread pool creates. so

in context_allocation function

  • add me (pthread_self) into the list

in context_free function

  • delete_me (pthread_self) from the list.

now if the main thread (not part of the thread pool) or some other thread
wants to cancel the thread pool, it will have to traverse the list and
pthread_cancel (thread_id from table entry) each one. QNX should have a
clean thread_pool_stop though. I mean they have a thread_pool_start.

We are working on ameliorating this situation, for now your
technique is really the only option. In the future you will
be able to call thread_pool_destroy() and it will in turn call
out to the unblock() handler you provide for each created
thread which is running. Unfortunately, right now the
thread_pool_destroy() call just blasts the allocated
structures away.

Other requests for features that people using thread pools would
like to see while I’m grunging around in that code? No
guarantees, but all reasonable offers will be considered =;-)

Thomas