Pithikos / C-Thread-Pool

A minimal but powerful thread pool in ANSI C
MIT License
2.06k stars 603 forks source link

question about threads_keepalive variable. #88

Open wind0ws opened 4 years ago

wind0ws commented 4 years ago

Hi, thanks for this awesome lib.

In thpool.c (line 37), here is static volatile int threads_keepalive; , why not put threads_keepalive on struct thpool_?

Assume the following scenario:

  1. Create thread pool A (Now threads_keepalive is set to 1);
  2. Call add_task on thread pool A;
  3. Create thread pool B (Now threads_keepalive is set to 1);
  4. Call add_task on thread pool B;
  5. Destroy thread pool A (Now threads_keepalive is set to 0);
  6. Call add_task on thread pool B ; ( task won't execute, because of threads_keepalive == 0 )
forGGe commented 3 years ago

Just stumbled with similar issue. In my application, thread pool B isn't scheduling tasks if thread pool A is destroyed.