Ds Unit 2
Ds Unit 2
Introduction of threads
A thread is a light weight process
Types of Thread
1. User Level Thread
The Kernel not aware of the existence of The Kernel maintain the process and thread
Thread
Thread switching not require Kernel mode Switching between threads requires the Kernel
privileges privileges
Combined Threads
• Overall system performance can be improved if processes are moved from heavily
loaded to lightly loaded machines.
Code migration dynamically configuring a client to communicate to a server. The client first
fetches the necessary software then invokes the server. A process have three segments.
2. Load distribution
3. Save valuable server time
4. Improve performance of
a. Network
b. Speed
c. Channels
d. Traffic
Application
Clock synchronization is a problem from computer science and engineering which deals with
the idea that internal clocks of several computers may differ. Even when initially set accurately,
real clocks will differ after some amount of time due to clock drift, caused by clocks counting
time at slightly different rates. There are several problems that occur as a repercussion of clock
rate differences and several solutions, some being more appropriate than others in certain
contexts.
Computer Clock
All computers have a circuit for keeping track of times.
A computer time is a machined quartz crystal, usually a quartz crystal, oscillating at a
well-defined frequency. A timer is associated with two registers: a counter and a
holding register, and counter decreasing one at each oscillation.
When the counter gets to zero, an interruption is generating and is count as one clock
tick.
ROM BIOS and time information is managed by CMOS battery
Crystals run at slightly different rates, the difference in time value known as a clock
skew.
Clock skew causes time-related failures.
Clock Drifting
The relation between clock time and UTC (Universal Coordinated Time) when clocks
tick at different rates
Algorithm:
1. A machine sends a request to the time server at least every d/2r seconds, where d is
the maximum difference allowed between a clock and the UTC;
2. The time server sends a reply message with the current UTC when receives the
request;
3. The machine measures the time delay between time server’s sending the message
and the machine’s receiving the message. Then, it uses the measure to adjust the
clock.
Cristian’s algorithm (2) - Getting the current time from a time server
c) Based on the answer it computes an average time and tells all the other machines to
change their clocks.
A condition in which there is a set of processes and only one of them is able to access
a given resources or perform a given function at a time.
Protects from others to interfere and waiting for to free
The major differences comparing with the single processor ME problem are:
1. there is no shared memory and
2. there is no common physical clock
Two kinds of algorithms:
1. Logical clock based
2. Token based.
Mutual Exclusion: guarantee that only one request access the Critical Region at a time.
Freedom from deadlock: two or more sites (hosts) should not endlessly wait for msg’s
that will never arrive.
Freedom from starvation: a site should not be forced to wait indefinitely to access CR.
Fairness: requests must be executed in the order they are made. (fairness freedom of
starvation, but not reverse)
Fault tolerance: in the case of failure, the algorithm can reorganize itself so that it
continues to function without any disruption.
1. Centralized Algorithm
2. Distributed Algorithm
3. Token Ring Algorithm
Centralized Algorithm
When a process wants to enter a critical region it builds a message and sends the
message to all other processes.
When a process receives a request message from another process, three situation
may be possible:
1. If the receiver not in the critical region and does not want to enter it, it sends
back an “OK” message to the sender.
2. If the receiver already in critical region, it does not reply, instead, it already in
the queues for requesting the process.
3. If the receiver also in critical region then receiver time-stamp is compare with
sender as well as all the process under critical region, the lowest time-stamp
allow permission for mutual exclusion.
Example:
CASE 1-
In Distributed System, suppose P2 and P5 is in Critical Region. Token are started from P1
using clock-wise direction when he reached at process P2, P2 already demanded for
resource R1 so now P2 is in Critical Region and using R1. After completion P2 free to R1 and
now “Token” again move to next process P3.
After processing of P2, Token passed to P3 but P3 not in Critical Region then P3 by pass to P4
again P4 not in Critical Region, Token passed to P5.
CASE 3
Now P5 already in Critical Region so Token assigned to process P5 for executing its job using
resources R1
An election algorithm determines which process will play the role of coordinator or
server. All processes need to agree on the selected process. Any process can start an
election,
We have two election algorithms for two different configurations of distributed
system.
1. The Bully Algorithm
Bully Algorithm
Bully Algorithm starts its process of selecting of coordinator when a working process
notices that the coordinator is not responding to it and then initiates an election. The
selection of a coordinator sends an election message to all the other available processes. If
none of the process responds to its message, the process itself wins the election and
becomes the coordinator.
Meanwhile, if any process that has a higher ID than the initiating process answers, it takes
charge of initiating the process. In this algorithm, the bully guy that is the participating
Ring Algorithm
In distributed system where many processes are working, for to avoid deadlock
condition and proper process synchronization, algorithm elected a coordinator for
monitoring on other processes
Ring Algorithm starts its process of selecting of coordinator, any process connected
in the ring notices that the coordinator is not functioning. The initiating process
then prepares an election message that contains its own process number and then
sends this message to its successor in the ring. If the successor is not functioning
then it skills that successor and sends it to the next one.
Every next process then adds its own process number to the message and delivers
the message to the next process connected in the ring. It continues until the
message again reaches the initiating process. Now the message consists of the
process number of all the functioning processes. The process that has the highest ID
wins the election. The initiating process then sends another message in the ring
about the winning process.
To choose coordinator, process (4) sends an ELECTION message to its successor with
its ID.
Process (6) is active and after attaching its ID move to nest Process (7), but process (7)
is not active so forward for Process (0)
Process (0) after attaching its ID forward for next process, so one by one all process
registered their identification.
The final information is again move to starting process – (4) , now process (4) have all
the information of processes, so select higher ID process as coordinator and inform to
all the process for selection of coordinator. As per the above diagram process (6) is
selected for its higher ID’s ( each steps will convert into diagram)
Transaction structure
o Flat vs Nested vs Distributed
Internal database consistency
o Semantic data control and integrity enforcement
Reliability protocols
o Atomicity and durability
o Local recovery protocols
o Global commit protocols
Concurrency control algorithms
Replica control protocols
Distributed transactions are those that involve more than one server. A client transaction
becomes distributed if it invokes operations in several different servers. There are two
different ways of distributed transactions:
1. Flat Transaction
2. Nested Transaction
Flat Transactions
In flat transaction, client makes requests to more than one server Means allowing
transactions to be composed of other transaction.
A flat transaction completes each of its requests before going on to the next one.
Each transaction accesses server’s objects sequentially.
Nested Transactions
In nested transaction, the top-level transaction can open sub-transactions and each sub-
transaction can open further sub-transactions.
Sub-transactions at the same level can run concurrently
As per the above diagram a transaction ‘T” open transactions T1 and T2 and both also have
sub-transactions (T11, T12 ) and (T21, T22)
1. Pessimistic
a. Two-Phase locking (2PL)
i. Centralized 2PL
ii. Distributed 2PL
b. Timestamp Ordering (TO)
i. Basic TO
ii. Multi-version TO
iii. Conservative TO
c. Hybrid
2. Optimistic
a. Locking and TO based
online-pdf-no-copy.com