Sie sind auf Seite 1von 19

Operating System

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

operating system Threads

THREAD ?
Threadisaflowofexecutionthroughtheprocesscode,withitsown
programcounter,systemregistersandstack
Threadsprovideawaytoimproveapplicationperformancethrough
parallelism.
Eachthreadbelongstoexactlyoneprocessandnothreadcanexist
outsideaprocess.Eachthreadrepresentsaseparateflowofcontrol.

Threadshavebeen
successfullyusedin
implementingnetwork
serversandweb
server.
operating system Threads

Process vs. Thread

operating system Threads

Process vs. Thread


Threads are easier to create than processes since they don't require a
separate address space.
Multithreading requires careful programming since threads share data
strucures that should only be modified by one thread at a time. Unlike
threads, processes don't share the same address space.
Threads are considered lightweight because they use far
less resources than processes.
Processes are independent of each other. Threads, since they share
the same address space are interdependent, so caution must be taken
so that different threads don't step on each other. This is really another
way of stating #2 above.
A process can consist of multiple threads.
operating system Threads

Advantages of Thread
Threadminimizescontextswitchingtime.
Useofthreadsprovidesconcurrencywithinaprocess.
Efficientcommunication.
Economy Itismoreeconomicaltocreateandcontextswitchthreads.
Utilizationofmultiprocessorarchitecturestoagreaterscaleandefficiency

operating system Threads

User Level Thread


Advantages
1.
2.
3.
4.

ThreadswitchingdoesnotrequireKernelmodeprivileges.
Userlevelthreadcanrunonanyoperatingsystem.
Schedulingcanbeapplicationspecificintheuserlevelthread.
Userlevelthreadsarefasttocreateandmanage

Disadvantages
1. Inatypicaloperatingsystem,
mostsystemcallsareblocking.
2. Multithreadedapplicationcannot
takeadvantageof
multiprocessing.

operating system Threads

Kernel Thread
Advantages
1.
2.
3.

Kernelcansimultaneouslyschedulemultiplethreadsfromthe
sameprocessonmultipleprocesses.
Ifonethreadinaprocessisblocked,theKernelcanschedule
anotherthreadofthesameprocess.
Kernelroutinesthemselvescanmultithreaded.

Disadvantages
1.
2.

Kernelthreadsaregenerallyslowertocreateandmanagethan
theuserthreads.
Transferofcontrolfromonethreadtoanotherwithinsame
processrequiresamodeswitchtotheKernel.

operating system Threads

User v.s. Kernel Thread

operating system Threads

10

Multithreading Models
Someoperatingsystemprovidesacombineduserlevelthread
andKernellevelthreadfacility.
Multiplethreadswithinthesameapplicationcanruninparallel
onmultipleprocessorsandablockingsystemcallneednot
blocktheentireprocess.

Therearethreetypes
1. Manytomanyrelationship.
2. Manytoonerelationship.
3. Onetoonerelationship.
operating system Threads

11

Many to One

operating system Threads

12

One to One

operating system Threads

13

Many to Many

operating system Threads

14

Two Level Model

operating system Threads

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/

operating system Threads

18

Next Week Assignment


(no submission just do it )
http://www.programmerinterview.com/index.php/operatingsystems/example-of-threading-and-synchronization-2/
READ, UNDERSTAND, IMPLEMENT THE CODE, and ANALYZE

operating system Threads

19

if you have spare time


1. http://docs.oracle.com/javase/7/docs/technotes/guides
/management/jconsole.html
2. Performancemonitor ResourcemonitoronWindows
3. https://technet.microsoft.com/en
us/library/bb896645.aspx
4. http://www.cyberciti.biz/tips/toplinuxmonitoring
tools.html
5. http://www.nirsoft.net/utils/process_threads_view.html

Onceagainifyouhavesparetime

Das könnte Ihnen auch gefallen