Anda di halaman 1dari 14

UNIT 2 and UNIT 3 Part - A

1. What is a thread?

A thread otherwise called a lightweight process (LWP) is a basic unit o !PU utili"ation# it co$prises o a thread id# a progra$ counter# a register set and a stac%& It shares with other threads belonging to the sa$e process its code section# data section# and operating s'ste$ resources such as open iles and signals&

2. What are the benefits of multithreaded programming?

The bene its o $ultithreaded progra$$ing can be bro%en down into our $a(or categories)

*esponsi+eness *esource sharing ,cono$' Utili"ation o $ultiprocessor architectures

3.Compare user threads and kernel threads.

User threads User threads are supported abo+e the %ernel and are i$ple$ented b' a thread librar' at the user le+el Thread creation . scheduling are done in the user space# without %ernel inter+ention& There ore the' are ast to create and $anage /loc%ing s'ste$ call will cause the entire process to bloc%

Kernel threads -ernel threads are supported directl' b' the operating s'ste$ Thread creation# scheduling and $anage$ent are done b' the operating s'ste$& There ore the' are slower to create . $anage co$pared to user threads I the thread per or$s a bloc%ing s'ste$ call# the %ernel can schedule another thread in the application or e0ecution

4.Define thread cancellation

target thread.

The thread cancellation is the tas% o ter$inating a thread be ore it has co$pleted& A thread that is to be cancelled is o ten re erred to as the target thread& 1or e0a$ple# i $ultiple threads are concurrentl' searching through a database and one thread returns the result# the re$aining threads $ight be cancelled&

!.What are the different "a#s in "hich a thread can be cancelled?

!ancellation o a target thread $a' occur in two di erent scenarios)


Asynchronous cancellation: 2ne thread i$$ediatel' ter$inates the target thread is called as'nchronous cancellation& Deferred cancellation: The target thread can periodicall' chec% i it should ter$inate# allowing the target thread an opportunit' to ter$inate itsel in an orderl' ashion&

$.Define C%U scheduling.

!PU scheduling is the process o switching the !PU a$ong +arious processes& !PU scheduling is the basis o $ultiprogra$$ed operating s'ste$s& /' switching the !PU a$ong processes# the operating s'ste$ can $a%e the co$puter $ore producti+e&

&.What is preempti'e and nonpreempti'e scheduling?

Under nonpree$pti+e scheduling once the !PU has been allocated to a process# the process %eeps the !PU until it releases the !PU either b' ter$inating or switching to the waiting state&

Pree$pti+e scheduling can pree$pt a process which is utili"ing the !PU in between its e0ecution and gi+e the !PU to another process&

(.What is a Dispatcher?

The dispatcher is the $odule that gi+es control o the !PU to the process selected b' the short-ter$ scheduler& This unction in+ol+es)

3witching conte0t 3witching to user $ode 4u$ping to the proper location in the user progra$ to restart that progra$&

).What is dispatch latenc#?

The ti$e ta%en b' the dispatcher to stop one process and start another running is %nown as dispatch latenc'&

56&What are the +arious scheduling criteria or !PU scheduling7

The +arious scheduling criteria are


!PU utili"ation Throughput Turnaround ti$e Waiting ti$e *esponse ti$e

11.Define throughput?

Throughput in !PU scheduling is the nu$ber o processes that are co$pleted per unit ti$e& 1or long processes# this rate $a' be one process per hour8 or short transactions# throughput $ight be 56 processes per second&

12.What is turnaround time?

Turnaround ti$e is the inter+al ro$ the ti$e o sub$ission to the ti$e o co$pletion o a process& It is the su$ o the periods spent waiting to get into $e$or'# waiting in the read' 9ueue# e0ecuting on the !PU# and doing I:2&

13.Define race condition.

When se+eral process access and $anipulate sa$e data concurrentl'# then the outco$e o the e0ecution depends on particular order in which the access ta%es place is called race condition& To a+oid race condition# onl' one process at a ti$e can $anipulate the shared +ariable&

14.What is critical section problem?

!onsider a s'ste$ consists o ;n; processes& ,ach process has seg$ent o code called a critical section# in which the process $a' be changing co$$on +ariables# updating a table# writing a ile& When one process is e0ecuting in its critical section# no other process can allowed to e0ecute in its critical section&

1!.What are the re*uirements that a solution to the critical section problem must satisf#?

The three re9uire$ents are

<utual e0clusion Progress /ounded waiting

1$.Define entr# section and e+it section.

The critical section proble$ is to design a protocol that the processes can use to cooperate& ,ach process $ust re9uest per$ission to enter its critical section& The section o the code i$ple$enting this re9uest is the entr' section& The critical section is ollowed b' an e0it section& The re$aining code is the re$ainder section&

1&.,i'e t"o hard"are instructions and their definitions "hich can be used for implementing mutual e+clusion.

TestAnd3et

boolean TestAnd3et (boolean .target) = boolean r+ > target8 target > true8 return r+8 ?

3wap

+oid 3wap (boolean .a# boolean .b) =

boolean te$p > a8 a > b8 b > te$p8 ?

1(.What is semaphores?

A se$aphore ;3@ is a s'nchroni"ation tool which is an integer +alue that# apart ro$ initiali"ation# is accessed onl' through two standard ato$ic operations8 wait and signal& 3e$aphores can be used to deal with the n-process critical section proble$& It can be also used to sol+e +arious s'nchroni"ation proble$s&

The classic de inition o ;wait@ wait (3) = while (3A>6) 8 3--8 ? The classic de inition o ;signal@ signal (3) = 3BB8 ?

1).Define bus# "aiting and spinlock.

When a process is in its critical section# an' other process that tries to enter its critical section $ust loop continuousl' in the entr' code& This is called as bus' waiting and this t'pe o se$aphore is also called a spinloc%# because the process while waiting or the loc%&

2-. .o" can "e sa# the /irst Come /irst 0er'ed scheduling algorithm is non preempti'e?

2nce the !PU has been allocated to a process# that process %eeps the !PU until it releases the !PU# either b' ter$inating or b' re9uesting I:2& 3o we can sa' the 1irst !o$e 1irst 3er+ed scheduling algorith$ is non pree$pti+e&

21.What is "aiting time in C%U scheduling?

Waiting ti$e is the su$ o periods spent waiting in the read' 9ueue& !PU scheduling algorith$ a ects onl' the a$ount o ti$e that a process spends waiting in the read' 9ueue&

22. What is 1esponse time in C%U scheduling?

*esponse ti$e is the $easure o the ti$e ro$ the sub$ission o a re9uest until the irst response is produced& *esponse ti$e is a$ount o ti$e it ta%es to start responding# but not the ti$e that it ta%es to output that response&

23. Differentiate long term scheduler and short term scheduler

The long-ter$ scheduler or (ob scheduler selects processes ro$ the (ob pool and loads the$ into $e$or' or e0ecution& The short-ter$ scheduler or !PU scheduler selects ro$ a$ong the process that are read' to e0ecute# and allocates the !PU to one o the$&

24. Write some classical problems of s#nchroni2ation?

The /ounded-/u er Proble$ The *eaders-Writers Proble$ The Cining Philosophers Proble$

2!. When the error "ill occur "hen "e use the semaphore?

i& When the process interchanges the order in which the wait and signal operations on the se$aphore $ute0& ii& When a process replaces a signal ($ute0) with wait ($ute0)& iii& When a process o$its the wait ($ute0)# or the signal ($ute0)# or both&

2$.What is 3utual 4+clusion?

A wa' o $a%ing sure that i one process is using a shared $odi iable data# the other processes will be e0cluded ro$ doing the sa$e thing& ,ach process e0ecuting the shared data +ariables e0cludes all others ro$ doing so si$ultaneousl'& This is called $utual e0clusion&

2&.Define the term critical regions?

!ritical regions are s$all and in re9uent so that s'ste$ through put is largel' una ected b' their e0istence& !ritical region is a control structure or i$ple$enting $utual e0clusion o+er a shared +ariable&

2(.What are the dra"backs of monitors?

5&<onitor concept is its lac% o i$ple$entation $ost co$$onl' used progra$$ing languages& 2&There is the possibilit' o deadloc%s in the case o nested $onitors calls&

2).What are the t"o le'els in threads?

Thread is i$ple$ented in two wa's&

5&User le+el 2&-ernel le+el

3-. What is a ,antt chart?

A two di$ensional chart that plots the acti+it' o a unit on the D-a0is +ersus the ti$e on the E-a0is& The chart 9uic%l' represents how the acti+ities o the units are seriali"ed&

31.Define deadlock.

A process re9uests resources8 i the resources are not a+ailable at that ti$e# the process enters a wait state& Waiting processes $a' ne+er again change state# because the resources the' ha+e re9uested are held b' other waiting processes& This situation is called a deadloc%&

32.What is the se*uence in "hich resources ma# be utili2ed?

Under nor$al $ode o operation# a process $a' utili"e a resource in the ollowing se9uence)

*e9uest) I the re9uest cannot be granted i$$ediatel'# then the re9uesting process $ust wait until it can ac9uire the resource& Use) The process can operate on the resource& *elease) The process releases the resource&

33.What are conditions under "hich a deadlock situation ma# arise?

A deadloc% situation can arise i the ollowing our conditions hold si$ultaneousl' in a s'ste$) 5& 2& 3& G& <utual e0clusion Fold and wait No pre-e$ption !ircular wait

34.What is a resource5allocation graph?

Ceadloc%s can be described $ore precisel' in ter$s o a directed graph called a s'ste$ resource allocation graph& This graph consists o a set o +ertices H and a set o edges ,& The set o +ertices H is partitioned into two di erent t'pes o nodes8 P the set consisting o all acti+e processes in the s'ste$ and * the set consisting o all resource t'pes in the s'ste$&

3!.Define re*uest edge and assignment edge.

A directed edge ro$ process Pi to resource t'pe *( is denoted b' PiI*(8 it signi ies that process Pi re9uested an instance o resource t'pe *( and is currentl' waiting or that resource& A directed edge ro$ resource t'pe *( to process Pi is denoted b' *(IPi# it signi ies that an instance o resource t'pe has been allocated to a process Pi& A directed edge PiI*( is called a re9uest edge& A directed edge *(IPi is called an assign$ent edge&

3$.What are the methods for handling deadlocks?

The deadloc% proble$ can be dealt with in one o the three wa's)

Use a protocol to pre+ent or a+oid deadloc%s# ensuring that the s'ste$ will ne+er enter a deadloc% state& Allow the s'ste$ to enter the deadloc% state# detect it and then reco+er& Ignore the proble$ all together# and pretend that deadloc%s ne+er occur in the s'ste$&

3&.Define deadlock pre'ention.

Ceadloc% pre+ention is a set o $ethods or ensuring that at least one o the our necessar' conditions li%e $utual e0clusion# hold and wait# no pre-e$ption and circular

wait cannot hold& /' ensuring that that at least one o these conditions cannot hold# the occurrence o a deadloc% can be pre+ented&

3(.Define deadlock a'oidance.

An alternati+e $ethod or a+oiding deadloc%s is to re9uire additional in or$ation about how resources are to be re9uested& ,ach re9uest re9uires the s'ste$ consider the resources currentl' a+ailable# the resources currentl' allocated to each process# and the uture re9uests and releases o each process# to decide whether the could be satis ied or $ust wait to a+oid a possible uture deadloc%&

3).What are a safe state and an unsafe state?

A state is sa e i the s'ste$ can allocate resources to each process in so$e order and still a+oid a deadloc%& A s'ste$ is in sa e state onl' i there e0ists a sa e se9uence& A se9uence o processes AP5#P2#J&PnK is a sa e se9uence or the current allocation state i # or each Pi# the resource that Pi can still re9uest can be satis ied b' the current a+ailable resource plus the resource held b' all the P(# with (Ai& i no such se9uence e0ists# then the s'ste$ state is said to be unsa e&

4-.What is banker6s algorithm?

/an%er@s algorith$ is a deadloc% a+oidance algorith$ that is applicable to a resource-allocation s'ste$ with $ultiple instances o each resource t'pe& The two algorith$s used or its i$ple$entation are)

Safety algorithm: The algorith$ or inding out whether or not a s'ste$ is in a sa e state&

Resource-request algorithm: i the resulting resource-allocation is sa e# the transaction is co$pleted and process Pi is allocated its resources& I the new state is unsa e Pi $ust wait and the old resource-allocation state is restored&

41.Define logical address and ph#sical address.

An address generated b' the !PU is re erred as logical address& An address seen b' the $e$or' unit that is the one loaded into the $e$or' address register o the $e$or' is co$$onl' re erred to as ph'sical address&

42.What is logical address space and ph#sical address space?

The set o all logical addresses generated b' a progra$ is called a logical address space8 the set o all ph'sical addresses corresponding to these logical addresses is a ph'sical address space&

43.What is the main function of the memor#5management unit?

The runti$e $apping ro$ +irtual to ph'sical addresses is done b' a hardware de+ice called a $e$or' $anage$ent unit (<<U)&

44.What are the methods for dealing the deadlock problem?

i& Use a protocol to ensure that the s'ste$ will ne+er enter a deadloc% state& ii& Allow the s'ste$ to enter the deadloc% state and then reco+er& iii& Ignore the proble$ all together# and pretend that deadloc%s ne+er occur in the s'ste$&

4!.Differentiate deadlock and star'ation.

A set o processes is in deadloc% state when e+er' process in the set is waiting or an e+ent that can be caused onl' b' the other process in the set& 3tar+ation or inde inite bloc%ing is a situation where processes wait inde initel' within the se$aphore&

*ead $ore) !352L2 - 2P,*ATINM 3D3T,<3 - Anna Uni+ersit' ,ngineering Nuestion /an% G U http)::9uestionban%Gu&in:inde0&php7 action>+iew.listid>2OG.sub(ect>O3.se$ester>G6Pi0""5*01l1L-Q Under !reati+e !o$$ons License) Attribution ,nter to win a ree tech boo% 565 1ree Tech /oo%s

Anda mungkin juga menyukai