Module 2 Multi Threaded Programming
Module 2 Multi Threaded Programming
Multi-threaded Programming
Overview
Multithreading models
Thread Libraries
Threading issues.
‣ several threads operate in the kernel, and each thread performs a specific task,
such as managing devices or interrupt handling.
‣ For example Solaris creates a set of threads in the kernel specifically for interrupt
handling;
‣ Linux uses a kernel thread for managing the amount of free memory in the system.
The trend towards multicore systems has placed pressure on system designers as well as
application programmers to make better use of the multiple computing cores.
‣ Designers of operating systems must write scheduling algorithms that use multiple
processing cores to allow the parallel execution
‣application programmers challenge is to modify existing programs as well as design
new programs that are multithreaded to take advantage of multicore systems.
TYPES OF THREADS
User Level Threads (User managed threads)
Kernel Level Threads (Operating System managed threads acting on kernel, an
operating system core)
All contemporary operating systems-including Windows XP, Linux, Mac OS X,
Solaris, and Tru64 UNIX (formerly Digital UNIX)-support kernel threads.
A relationship must exist between user threads and kernel threads.
Three common ways of establishing such a relationship
Advantages:
1. This model provides more concurrency than the many-to-one model.
2. It also allows another thread to run when a thread makes a blocking system call.
3. It supports multiple threads to execute in parallel on multiprocessors.
‣ Similar to Many to Many, except that it allows a user thread to be bound to kernel
thread
‣ Examples
- IRIX
- HP-UX
- Solaris 8 and earlier
to the kernel.
proceeding.
Thread cancellation
Signal handling
Thread pools
If one thread in a program calls fork(),does the new process duplicates all threads or is the
new process single-threaded?
Some UNIX systems have chosen to have two versions of fork(),one that duplicates all
threads and another duplicates only thread that invoked the fork() system call.
Which of the two versions of fork() to use depends on the application.
If thread invokes the exec system call the program specified in the parameter to
‣ Servicing a request with an existing thread is usually faster than waiting to create a
thread.
‣ The pool limits the no. of threads that exist at any one point.
Department of CSE- Data Science
No. of threads in the pool can be based on actors such as
‣ no. of CPUs