1
Threads
Asmaa Mowafaq ALQassab
Supervised by
Prof. Dr. Manar Kashmoola
2
Threads
 Process
 A program in execution.
 Process table
 Entries to CPU register values, memory maps, open
files, accounting info., privileges, etc.
 Cost highly
 Saving CPU context, e.g., register values, program
counter, stack pointers, etc.
 Swapping processes.
3
Threads and Processes
The Thread Model
 Items shared by all threads in a process
 Items private to each thread
Problems with Processes
 Creating and managing processes is generally
regarded as an expensive task.
 Making sure all the processes peacefully co-
exist on the system is not easy.
 Threads can be thought of as an “execution
of a part of a program (in user-space)”.
 Rather than make the OS responsible for
concurrency transparency, it is left to the
individual application to manage the creation
and scheduling of each thread.
Thread Usage in Non-distributed Systems
Context switching as the result of IPC
Threaded applications often run faster than non-
threaded applications (as context-switches between
kernel and user-space are avoided).
7
Thread Implementation
 Tow approaches to implement a thread
package
 To construct a thread library that is executed
entirely in user mode.
 To have the kernel be aware of threads and
schedule them.
Thread Implementation
user level library: switching in a few instructions, no change in memory maps
etc. but a blocking system call blocks the entire process.
O.S. kernel level : no problem with blocking system call but every thread
operation has to be carried out by the kernel, so switching context similar to
process.
Combining kernel-level lightweight processes and user-level
threads.
LightWeight Processes (LWP)
•Manipulation of threads at user level
•A blocking call doesn’t suspend the entire
process
9
Threads in Distributed Systems
 Important characteristic: a blocking call in a
thread does not result in the entire process
being blocked.
 This leads to the key characteristic of threads
within distributed systems:
 “We can now express communications in the form
of maintaining multiple logical connections at the
same time (as opposed to a single, sequential,
blocking process).”
10
Example: MT Clients and Servers
 Mutli-Threaded Client: to achieve acceptable levels of
perceived performance, it is often necessary to hide
communications latencies.
 Consequently, a requirement exists to start
communications while doing something else.
 Example: modern web browsers.
 This leads to the notion of “truly parallel streams of
data” arriving at a multi-threaded client application.
11
Example: MT-Servers
 Although threading is useful on clients, it is
much more useful in distributed systems
servers.
 The main idea is to exploit parallelism to
attain high performance.
 A typical design is to organize the server as a
single “dispatcher” with multiple threaded
“workers”, as diagrammed overleaf.
Multithreaded Servers (1)
A multithreaded server (i.e. file server) organized in a
dispatcher/worker model
The true benefit from multithreading in DS is having multithreaded servers

thread_ multiprocessor_ scheduling_a.ppt

  • 1.
    1 Threads Asmaa Mowafaq ALQassab Supervisedby Prof. Dr. Manar Kashmoola
  • 2.
    2 Threads  Process  Aprogram in execution.  Process table  Entries to CPU register values, memory maps, open files, accounting info., privileges, etc.  Cost highly  Saving CPU context, e.g., register values, program counter, stack pointers, etc.  Swapping processes.
  • 3.
  • 4.
    The Thread Model Items shared by all threads in a process  Items private to each thread
  • 5.
    Problems with Processes Creating and managing processes is generally regarded as an expensive task.  Making sure all the processes peacefully co- exist on the system is not easy.  Threads can be thought of as an “execution of a part of a program (in user-space)”.  Rather than make the OS responsible for concurrency transparency, it is left to the individual application to manage the creation and scheduling of each thread.
  • 6.
    Thread Usage inNon-distributed Systems Context switching as the result of IPC Threaded applications often run faster than non- threaded applications (as context-switches between kernel and user-space are avoided).
  • 7.
    7 Thread Implementation  Towapproaches to implement a thread package  To construct a thread library that is executed entirely in user mode.  To have the kernel be aware of threads and schedule them.
  • 8.
    Thread Implementation user levellibrary: switching in a few instructions, no change in memory maps etc. but a blocking system call blocks the entire process. O.S. kernel level : no problem with blocking system call but every thread operation has to be carried out by the kernel, so switching context similar to process. Combining kernel-level lightweight processes and user-level threads. LightWeight Processes (LWP) •Manipulation of threads at user level •A blocking call doesn’t suspend the entire process
  • 9.
    9 Threads in DistributedSystems  Important characteristic: a blocking call in a thread does not result in the entire process being blocked.  This leads to the key characteristic of threads within distributed systems:  “We can now express communications in the form of maintaining multiple logical connections at the same time (as opposed to a single, sequential, blocking process).”
  • 10.
    10 Example: MT Clientsand Servers  Mutli-Threaded Client: to achieve acceptable levels of perceived performance, it is often necessary to hide communications latencies.  Consequently, a requirement exists to start communications while doing something else.  Example: modern web browsers.  This leads to the notion of “truly parallel streams of data” arriving at a multi-threaded client application.
  • 11.
    11 Example: MT-Servers  Althoughthreading is useful on clients, it is much more useful in distributed systems servers.  The main idea is to exploit parallelism to attain high performance.  A typical design is to organize the server as a single “dispatcher” with multiple threaded “workers”, as diagrammed overleaf.
  • 12.
    Multithreaded Servers (1) Amultithreaded server (i.e. file server) organized in a dispatcher/worker model The true benefit from multithreading in DS is having multithreaded servers