Parallel and distributed computing lec 5
Parallel and distributed computing lec 5
computing
COMP3139
Agenda
• Thread in OS
• Its components
• Its types
• Multithread
• Benefits of thread
• Threads can share common data, so they do not need to use inter-
process Communication. Like the processes, threads also have
states like ready, executing, blocked, etc.
• Priority can be assigned to the threads just like the process, and
the highest priority thread is scheduled first.
Why Do We Need Thread?
• Like the process, a context switch occurs for the thread, and
register contents are saved.
• Stack Space
• Register Set
• Program Counter
Thread Implementation
• The first approach is to construct a thread library that is executed entirely in user
mode.
• The second approach is to have the kernel be aware of threads and schedule
them.
Types of Threads
• Because of the presence of only Program Counter, Register Set, and Stack
Space, it has a simple representation .
• The kernel knows about all the threads and manages them.
• The kernel-level thread offers a system call to create and manage the
threads from user-space.
• If there are several LWPs, then each of them executes the scheduler.
• The thread table, which is used to keep track of the current set of
threads, is thus shared by the LWPs.
• Enhanced throughput of the system: When the process is split into many
threads, and each thread is treated as a job.
• During a fork() call the issue that arises is whether the whole process
should be duplicated or just the thread which made the fork() call should
be duplicated.
• The exec() call replaces the whole process that called it including all the
threads in the process with a new program.
• In a single-process, single-
threaded environment all requests
to, e.g., the I/O interface blocks any
further progress in the process. Any
combination of a multi-process.
• A multi-process environment
requires an extensive support from
the underlying operating system.
Multithreaded Clients
• The static parts like the code segment and the static memory can be shared
between the two processes and does not require a copy of the memory.
• The process of forking a child process is not unique for Unix, but the exact
behavior is often quite platform dependent.