Beruflich Dokumente
Kultur Dokumente
thread
soni@its-sby.edu
Multi (programming-tasking-processing-threading)
Multiprogrammingreferstomultipleprogramsresidentinmainmemoryand
(apparentlybutnotexactly)runningatthesametime
Multitaskingreferstomultipleprocessesrunningsimultaneouslybysharing
theCPUtime
MultiprocessingreferstomultipleCPUs
Multithreadingisanexecutionmodelthatallowsasingleprocesstohave
multiplecodesegments(threads)runconcurrentlywithinthecontextof
thatprocess
MultiplethreadsofasingleprocesscansharetheCPUinasingleCPU
systemor(purely)runinparallelinamultiprocessingsystem
THREAD ?
Threadisaflowofexecutionthroughtheprocesscode,withitsown
programcounter,systemregistersandstack
Threadsprovideawaytoimproveapplicationperformancethrough
parallelism.
Eachthreadbelongstoexactlyoneprocessandnothreadcanexist
outsideaprocess.Eachthreadrepresentsaseparateflowofcontrol.
Threadshavebeen
successfullyusedin
implementingnetwork
serversandweb
server.
operating system Threads
Advantages of Thread
Threadminimizescontextswitchingtime.
Useofthreadsprovidesconcurrencywithinaprocess.
Efficientcommunication.
Economy Itismoreeconomicaltocreateandcontextswitchthreads.
Utilizationofmultiprocessorarchitecturestoagreaterscaleandefficiency
ThreadswitchingdoesnotrequireKernelmodeprivileges.
Userlevelthreadcanrunonanyoperatingsystem.
Schedulingcanbeapplicationspecificintheuserlevelthread.
Userlevelthreadsarefasttocreateandmanage
Disadvantages
1. Inatypicaloperatingsystem,
mostsystemcallsareblocking.
2. Multithreadedapplicationcannot
takeadvantageof
multiprocessing.
Kernel Thread
Advantages
1.
2.
3.
Kernelcansimultaneouslyschedulemultiplethreadsfromthe
sameprocessonmultipleprocesses.
Ifonethreadinaprocessisblocked,theKernelcanschedule
anotherthreadofthesameprocess.
Kernelroutinesthemselvescanmultithreaded.
Disadvantages
1.
2.
Kernelthreadsaregenerallyslowertocreateandmanagethan
theuserthreads.
Transferofcontrolfromonethreadtoanotherwithinsame
processrequiresamodeswitchtotheKernel.
10
Multithreading Models
Someoperatingsystemprovidesacombineduserlevelthread
andKernellevelthreadfacility.
Multiplethreadswithinthesameapplicationcanruninparallel
onmultipleprocessorsandablockingsystemcallneednot
blocktheentireprocess.
Therearethreetypes
1. Manytomanyrelationship.
2. Manytoonerelationship.
3. Onetoonerelationship.
operating system Threads
11
Many to One
12
One to One
13
Many to Many
14
15
Java Thread
Javathreadsmaybecreatedby:
ExtendingThreadclass
ImplementingtheRunnable interface
JavathreadsaremanagedbytheJVM.
LETS CODE
References
1. AbrahamSilberschatz, PeterBaerGalvin,GregGagne,
OperatingSystemConceptsWithJava,Wiley
2. Tutorialpoint.com
3. https://www.youtube.com/watch?v=E_Zp2d_STAo
4. http://www.programmerinterview.com/index.php/operating
systems/threadvsprocess/
18
19
Onceagainifyouhavesparetime