thread pool master mind

Hi,

I have a resource manager using a thread pool which works curiously.
To try to understand how are the thread pools managed, I wrote a very
simple resource manager using that.
The particularity of my application is that the thread which is
computing the received message create another thread to do the work and
waits for some events, a pulse in that case. I add that sometimes, it
works as I expect! I explain:

The files are thread_pool (server) and thread_poll_cl (client).

First test:
When I run thread_ pool, psin gives:

Tid priority state blocked
1 10r RECEIVE 1
2 10r RECEIVE 1

Ok

When I run thread_pool_cl, the thread 3 is created and psin gives:

Tid priority state blocked
1 10r RECEIVE 1
2 10r RECEIVE 4<-
3 25f NANOSLEEP

When the timer fires, psin gives:

Tid priority state blocked
1 10r RECEIVE 1
3 25r RECEIVE 1<-

Second test:
Now, suppose that 2 clients send a request:
we assume the following state before executing the clients:

Tid priority state blocked
1 10r RECEIVE 1
2 10r RECEIVE 1

Now I start the first client:

Tid priority state blocked
1 10r RECEIVE 1
2 10r RECEIVE 4<-
3 25f NANOSLEEP

I start the second client
Tid priority state blocked
1 10r CONDVAR B034BAE4
2 10r RECEIVE 4
3 25f NANOSLEEP
4 10r RECEIVE 1

First job is done:
Tid priority state blocked
2 25f NANOSLEEP
3 10r RECEIVE 1
4 10r RECEIVE 3
5 10r RECEIVE 1

After the work is done:

Tid priority state blocked
3 10r RECEIVE 1
5 10r RECEIVE 1

For the first test:

  1. Who is the process id 4, I don’t see it with psin?

  2. I though that low_water was the number of waiting threads. So, Why
    don’t the kernel create another waiting thread when thread 3 (created by
    one of the thread of the pool) is running because I think that thread 2
    is waiting on MY msgReceive(). So it’s not an available thread for the
    pool.

  3. After the work is done, Who is the thread 3 at priority 25 blocked on
    RECEIVE ?!?

Second test:

  1. Why thread 1 is blocked on CONDVAR. Is it because the resource
    manager received the same message twice? What is it afraid of?

  2. I always have ONE waiting thread (thread 4) created by the kernel.

  3. Why thread 5 is created only when job 1 is done (maybe 20 seconds
    later)?

  4. Thread 3 again! what does it do here! Why this thread is now at
    priority 10?

Thanks,
Alain.