As Solaris has many-to-many threading model/two level threading model, can you tell me how the user thread is mapped to a LWPs exactly? What is the algorithm that is is being followed? Is there any limit (that these many no of threads can only be mapped to one LWP & vice versa)?

Niyi Gbodimowo

The algorithm that is used is based on a combination of Solaris' doors IPC model and a simpler signals protocol. When you start a program that is linked with the thread library libpthread.so, the thread library automatically starts a background process - the dynamiclwps() or dynamic LWP scheduler which maps available LWPs to unbound user threads. It runs a tight loop and blocks on signotifywait(). Additionally, a small number of LWPs are shared between the kernel and the thread library. This is the doors thread pool.

As long as there are free LWPs, the unbound user threads are bound to a LWP. If a user thread blocks on some condition variable e.g I/O read, a LWP from the door thread pool will be dispatched to run any available user threads. If there are none, the LWP will wait on a timed (def. 5 minutes) condition variable before terminating/returning to the door thread pool. If the door thread pool is empty, the the kernel generates a SIGWAITING signal to the dynamiclwps().On receipt of a SIGWAITING signal, the dynamiclwps thread will create a new LWP.

As you can see, new LWP pool is replenished when kernel threads move to a SLEEP state and thread resources are conserved by cleaning up unused LWPs. Of course, you can use pthread_create(...) to create your threads such that they are mapped to LWPs immediately or you can use thr_create() to make full use of many-to-many thread mappings. If on the other hand, you wish to explicitly set the number of LWPs you want created, you can use thr_setconcurrency(n) where n is an integer that hints on the number of LWPs to create in the thread pool.

I hope that that was not too obscure!