Multi Threaded Programming
Multi Threaded Programming
• User-level threads implement in user-level libraries, rather than via systems calls,
• Thread switching does not need to call operating system and to cause interrupt to
the kernel.
• The kernel knows nothing about user-level threads and manages them as if they
were single-threaded processes.
Advantages of User level thread
• Context Switching
• Threads are very inexpensive to create and destroy
• Threads require space to store, the PC, the SP, and the general-purpose
registers,
• Threads do not require space to share memory information, Information
about open files of I/O devices in use, etc.
• it is much faster to switch between threads.• it is easier for a context switch
using threads.
• Sharing
• Treads allow the sharing of a lot resources that cannot be shared in process,
• For example, sharing code section, data section, Operating System resources
like open file etc
Disadvantages of Threads over Multiprocesses
• Blocking
• If the kernel is single threaded, a system call of one thread will block the
whole process and
• CPU may be idle during the blocking period.
• Security
• an extensive sharing among threads there is a potential problem of security.
• It is possible that one thread overwrites the stack of another thread
Benefits
• Responsiveness
• Multithreading is an interactive application, may allow a program to continue
running even if part of it is blocked, or is performing a lengthy operation.
• Resource Sharing
• The benefit of sharing code and data is that it allows. an application to have
several different threads of activity within the same address space.
• Economy
• in Solaris, creating a process is about thirty times slower than is creating
thread and context switching is about five times slower.
• Scalability
• Multithreading can be greatly increased in a multiprocessor architecture,
where threads may be running in parallel on different processors
Multithreaded server architecture