In: Computer Science
1.What are two differences between user-level threads and kernel-level threads? Under what circumstances is one type better than the other?
2.Describe the actions taken by a kernel to context switch between kernel level threads.
3.What resources are used when a thread is created? How do they differ from those used when a process is created?
4.Provide two programming examples in which multithreading provides better performance than a single-threaded solution.
5.Assume an operating system maps user-level threads to the kernel using the many-to-many model and the mapping is done through LWPs. Furthermore, the system allows developers to create real-time threads. Is it necessary to bind a real-time thread to an LWP? Explain
6.Windows Vista provides a lightweight synchronization tool called slim reader–writer locks. Whereas most implementations of reader–writer locks favor either readers or writers, or perhaps order waiting threads using a FIFO policy, slim reader–writer locks favor neither readers nor writers, nor are waiting threads ordered in a FIFO queue. Explain the benefits of providing such a synchronization tool.
1) User Level Thread Kernel Level Thread
(a) ULT are managed by user level libraries (a) KLT are managed by operating system ie kernel ( through system calls)
(b)Implementation is easy (b) its implementation is complex
(c) context switching is faster (c) context switching is slower
ULT is better as no H/w support is required whereas KLT requires H/w support
ULT is faster than KLT
KLT is better as in KLT if 1 thread is blocked ,it wont affect on other whereas in ULT if one thread is blocked entire process is blocked..
ULT thread is dependent thread as it depends on APIs libraries but KLT is Independent thread as every decision is taken by os itself
2) Actions taken by kernel to context switch between kernel threads : as mentioned before context switching is slower with respect to kernel thread as Kernel maintains context information for the process as a whole and for individual threads within process during context switching between kernel threads.
3)The resources used to create a thread are threadID,stack, set of register ,basically thread creation requires fewer resources as compared to process creation so thread creation is a light weight task.
process creation requires Process control block allocations which is larger than any database also memory allocation to program instruction and data is done which is time consuming yet heavy weight task of process creation with more resources.
4) two programming examples in which multithreading provides better performance than a single threaded solution are
a) Web servers - they basically serves web content or applications to clients who request for a service.
web servers performance will be better using multiithreads as multiple client request can be tackled by multiple threads whereas using single threaded solution will affect the performance as every time a new thread needs to be created to serve every new service requested by client..
b) Remote Procedural Callsystems which is also called as subroutine call or functional call - its client server mechanism model where a client makes a request to a server and server provides the results or the message
suppose single thread solution is used in RPC then for every client request thread will be suspended until the result is fetched by the server this makes it time consuming
but using multithread solution will increase the time efficiency of client server model by running several threads concurrently where other threads will provide messages to the client thus suspending of threads won't affect its performance.