Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Threads.ppt
1. Operating Systems
Threads
Dr. Suresh Kumar Bhardwaj
Professor, CSE
MRIIRS
Manav Rachna International Institute of
Research and Studies, Faridabad
2. Threads
• The general structure of a process assumes that the process has an
address space with a single sequential execution sequence. Which leads
to low resource utilization
• Thread is a mechanism to provide multiple execution control to the
processes
• Thread has the following benefits:
– Responsiveness
– Resource Sharing
– Economy
– Utilization of MP Architectures
• Threads are classified as:
– user threads and
– the kernel threads
4. User Level Threads
• Thread management done by user-level threads library rather than via
systems calls.
• Therefore, thread switching does not need to call operating system and to
cause interrupt to the kernel.
• In fact, the kernel knows nothing about user-level threads and manages
them as if they were single-threaded processes.
• Advantages :
– The most obvious advantage of this technique is that a user-level threads package can
be implemented on an Operating System that does not support threads.
– User-level threads do not require any modification to operating systems.
– Simple Representation : Each thread is represented simply by a PC, registers, stack and a
small control block, all stored in the user process address space.
– Simple Management : This simply means that creating a thread, switching between
threads and synchronization between threads can all be done without intervention of
the kernel.
5. – Fast and Efficient : Thread switching is not more expensive than a procedure call.
Disadvantages :
– There is a lack of coordination between threads and operating system kernel. Therefore,
process as whole gets one time slice irrespective of whether process has one thread or
even 1000 threads within it. It is up to each thread to relinquish control to other
threads.
– User-level threads require non-blocking systems call i.e., a multithreaded kernel.
Otherwise, entire process will be blocked in the kernel, even if there are runable threads
left in the processes. For example, if one thread causes a page fault, the process gets
blocked.
Three primary thread libraries:
– POSIX Pthreads
– Win32 threads
– Java threads
6. Kernel Level Threads
• The kernel knows about the threads and manages them.
• The kernel has a thread table that keeps track of all the threads in the system.
• In addition, the kernel also maintains the traditional process table to keep track of
the processes.
Advantages:
– Because kernel has full knowledge of all threads, Scheduler may decide to give more
time to a process having large number of threads than process having small number of
threads.
– Kernel-level threads are especially good for applications that frequently block.
Disadvantages:
– The kernel-level threads are slow and inefficient. For instance, threads operations are
hundred of times slower than that of user-level threads.
– Since kernel must manage and schedule threads as well as processes. It requires a full
thread control block (TCB) for each thread to maintain information about threads.
8. Many-to-One
• Many user-level threads mapped
to single kernel thread
• Examples:
– Solaris Green Threads
– GNU Portable Threads
9. One-to-One
• Each user-level thread maps to
kernel thread
• Examples
– Windows NT/XP/2000
– Linux
– Solaris 9 and later
10. Many-to-Many Model
• Allows many user level threads to
be mapped to many kernel
threads
• Allows the operating system to
create a sufficient number of
kernel threads
• Solaris prior to version 9
• Windows NT/2000 with the
ThreadFiber package
11. Java Threads
• Java threads are managed by the JVM
• Java threads may be created by:
– Extending Thread class
– Implementing the Runnable interface
13. References
• Operating System Concepts: Silberschatz,
Wiley India, 9th edition
Manav Rachna International Institute of
Research and Studies, Faridabad