Ds Ch3, Process
Ds Ch3, Process
12/24/2024 8:26:10 AM 2
Cont.
• a thread also executes independently from other threads; but no
need of a high degree of concurrency transparency thereby
resulting in better performance
• What is the difference b/n thread and process?
• threads can be used in both distributed and non distributed systems
• Threads in Non distributed Systems
• a process has an address space (containing program text and data)
and a single thread of control, as well as other resources such as
open files, child processes, accounting information, etc.
12/24/2024 8:26:10 AM 3
Process 1 Process 2 Process 3
processes each with one thread one process with three threads
12/24/2024 8:26:10 AM 4
each thread has its own program counter, registers, stack, and state; but
all threads of a process share address space, global variables and other
resources such as open files, etc.
12/24/2024 8:26:10 AM 5
Threads take turns in running
• Like a process, a thread executes its own piece of code,
independently from other threads. However, in contrast to
processes, no attempt is made to achieve a high degree of
concurrency transparency if this would result in performance
degradation.
• Threads allow multiple executions to take place in the same process
environment, called multi threading
• Thread Usage –Why do we need threads?
• e.g., a word processor has different parts for
• interacting with the user
• formatting the page as soon as changes are made
• timed savings (for auto recovery)
• spelling and grammar checking, etc.
12/24/2024 8:26:10 AM 6
1.Simplifying the programming model: since many activities are going
on at once more or less independently
2.They are easier to create and destroy than processes since they do
not have any resources attached to them
3.Performance improves by overlapping activities if there is too much
I/ O; i. e., to avoid blocking when waiting for input or doing
calculations, say in a spreadsheet
• 4. Real parallelism is possible in a multiprocessor system
12/24/2024 8:26:10 AM 7
In non distributed systems, threads can be used with shared data
instead of processes to avoid context switching overhead
interprocess communication (IPC).
12/24/2024 8:26:10 AM 8
Thread Implementation
• threads are usually provided in the form of a thread package
• the package contains operations to create and destroy a thread,
operations on synchronization variables such as mutexes and condition
variables
• two approaches of constructing a thread package
a. construct a thread library that is executed entirely in user mode (the
OS is not aware of threads)
• cheap to create and destroy threads; just allocate and free memory
• context switching can be done using few instructions; store and
reload only CPU register values
• disadvantage: invocation of a blocking system call will block the
entire process to which the thread belongs and all other threads in
that process
b. implement them in the OS’s kernel
• let the kernel be aware of threads and schedule them
• expensive for thread operations such as creation and deletion since
each requires a system call
12/24/2024 8:26:10 AM 9
Thread States
• New,
• running,
• waiting
• Blocked
• Timed waiting and
• Termination states
12/24/2024 8:26:10 AM 10
There are the following two ways to create a thread:
• By Extending Thread Class
• By Implementing Runnable Interface
• Thread Class
• Eg. class Multi extends Thread{
public void run(){
System.out.println("thread is running...");
}
public static void main(String args[]){
Multi t1=new Multi();
t1.start();
} }
12/24/2024 8:26:10 AM 11
class Multi3 implements Runnable{
public void run(){
System.out.println("thread is running...");
}
public static void main(String args[]){
Multi3 m1=new Multi3();
Thread t1 =new Thread(m1); // Using the constructor Thread(Runnabl
e r)
t1.start();
} }
12/24/2024 8:26:10 AM 12
• solution: use a hybrid form of user-level and kernel-level threads,
called lightweight process (LWP)
• Threads in Distributed Systems
• Multithreaded Clients
• consider a Web browser; fetching different parts of a page can
be implemented as a separate thread, each opening its own
TCP connection to the server
• each can display the results as it gets its part of the page
• parallelism can also be achieved for replicated servers since
each thread request can be forwarded to separate replicas
• Multithreaded Servers
• servers can be constructed in three ways
A. single-threaded process it gets a request, examines it, carries
it out to completion before getting the next request
12/24/2024 8:26:10 AM 13
b. Threads
• threads are more important for implementing servers
• e.g., a file server
• the dispatcher thread reads incoming requests for a file operation from clients and
passes it to an idle worker thread
C. finite-state machine
• if threads are not available
• it gets a request, examines it, tries to fulfill the request from cache, else
sends a request to the file system
Model Characteristics
Single-threaded process No parallelism, blocking system calls
Threads Parallelism, blocking system calls (thread only)
Finite-state machine Parallelism, non blocking system calls
12/24/2024 8:26:10 AM 14
3.2 Anatomy of Clients
Two issues: user interfaces and client-side software for
distribution transparency
A. User Interfaces
• to create a convenient environment for the interaction of a
human user and a remote server; e.g. mobile phones with
simple displays and a set of keys
• GUIs are most commonly used
• The X Window System (or simply X) as an example
• it has the X kernel: the part of the OS that controls the
terminal (monitor, keyboard, pointing device like a mouse)
and is hardware dependent
12/24/2024 8:26:10 AM 15
b. Client-Side Software for Distribution Transparency
• In addition to the user interface, parts of the processing and data level
in a client-server application are executed at the client side
12/24/2024 8:26:10 AM 16
3.3 Servers and Design Issues
3.3.1 General Design Issues
a. How to organize servers?
Iterative server
• the server itself handles the request and returns the result
Concurrent server
• it passes a request to a separate process or thread and waits for
the next incoming request; e.g., a multithreaded server;
b. Where do clients contact a server?
• using endpoints or ports at the machine where the server is
running where each server listens to a specific endpoint
• how do clients know the endpoint of a service?
• globally assign endpoints for well-known services; e.g. FTP is on
TCP port 21, HTTP is on TCP port 80
12/24/2024 8:26:10 AM 17
3.4 Code Migration
• so far, communication was concerned on passing data
• we may pass programs, even while running and in
heterogeneous systems
• code migration also involves moving data as well: when a
program migrates while running, its status, pending signals, and
other environment variables such as the stack and the program
counter also have to be moved
12/24/2024 8:26:10 AM 18
Reasons for Migrating Code
• To improve performance; move processes from heavily-loaded
to lightly-loaded machines (load balancing)
12/24/2024 8:26:10 AM 21
Migration can be
• sender-initiated: the machine where the code resides or is currently running;
e.g., uploading programs to a server; may need authentication or that the
client is a registered one; crawlers(computing a program to make index of
data ) to index Web pages
• receiver-initiated: by the target machine; e.g., Java Applets; easier to
implement
12/24/2024 8:26:10 AM 23
Types of Process-to-Resource Bindings
• Process migration is the process of transferring a process from one machine to another. The
goal of migration is to move processes from heavily loaded systems to lightly loaded systems to
improve performance and communication. This can be in 3 ways i.e.,:
A. Binding by identifier (the strongest): a resource is referred by its identifier; the process
requires that resource; e.g., a URL to refer to a Web page or an FTP server referred by its
Internet (IP) address
B. Binding by value (weaker): when only the value of a resource is needed; in this case another
resource can provide the same value; e.g., standard libraries of programming languages such as
C or Java which are normally locally available, but their location in the file system may vary
from site to site
C. Binding by type (weakest): a process needs a resource of a specific type; reference to local
devices, such as monitors, printer.
12/24/2024 8:26:10 AM 24
Resource-to-Machine Bindings
• Resource-to-machine bindings in a distributed system are how resources
relate to the hosting machine. The resource-to-machine binding determines
how a resource reference is changed. There are three types of resource-to-
machine bindings. i.e.
12/24/2024 8:26:09 AM 26
Thank You!
?
12/24/2024 8:26:10 AM 27