作业系统第04章的PPT

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Chapter4:Threads4.2!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Chapter4:Threads Overview MulticoreProgramming MultithreadingModels ThreadLibraries ImplicitThreading ThreadingIssues OperatingSystemExamples4.3!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Objectives Tointroducethenotionofathread—afundamentalunitofCPUutilizationthatformsthebasisofmultithreadedcomputersystems TodiscusstheAPIsforthePthreads,Windows,andJavathreadlibraries Toexploreseveralstrategiesthatprovideimplicitthreading Toexamineissuesrelatedtomultithreadedprogramming TocoveroperatingsystemsupportforthreadsinWindowsandLinux4.4!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Motivation Mostmodernapplicationsaremultithreaded Threadsrunwithinapplication Multipletaskswiththeapplicationcanbeimplementedbyseparatethreads Updatedisplay Fetchdata Spellchecking Answeranetworkrequest Processcreationisheavy-weightwhilethreadcreationislight-weight Cansimplifycode,increaseefficiency Kernelsaregenerallymultithreaded4.5!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!SingleandMultithreadedProcessesregisterscodedatafilesstackregistersregistersregisterscodedatafilesstackstackstackthreadthreadsingle-threadedprocessmultithreadedprocess4.6!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!MultithreadedServerArchitectureclient(1)request(2)createnewthreadtoservicetherequest(3)resumelisteningforadditionalclientrequestsserverthread4.7!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Benefits Responsiveness–mayallowcontinuedexecutionifpartofprocessisblocked,especiallyimportantforuserinterfaces
 ResourceSharing–threadsshareresourcesofprocess,easierthansharedmemoryormessagepassing
 Economy–cheaperthanprocesscreation,threadswitchingloweroverheadthancontextswitching
 Scalability–processcantakeadvantageofmultiprocessorarchitectures
4.8!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!MulticoreProgramming Parallelismimpliesasystemcanperformmorethanonetasksimultaneously Concurrencysupportsmorethanonetaskmakingprogress Singleprocessor/core,schedulerprovidingconcurrency Typesofparallelism Dataparallelism–distributessubsetsofthesamedataacrossmultiplecores,sameoperationoneach! Taskparallelism–distributingthreadsacrosscores,eachthreadperforminguniqueoperation Asthenumberofthreadsgrows,sodoesarchitecturalsupportforthreading CPUshavecoresaswellashardwarethreads! ConsiderOracleSPARCT4with8cores,and8hardwarethreadspercore4.9!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Concurrencyvs.Parallelism Concurrentexecutiononsingle-coresystem:! Parallelismonamulti-coresystem:!T1T2T3T4T1T2T3T4T1singlecoretime…T1T3T1T3T1core1T2T4T2T4T2core2time……4.10!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!MulticoreProgramming Multicoreormultiprocessorsystemsputtingpressureonprogrammerstoadapttheirappliationstosupportmultithreading Challengesinclude: Dividingactivities–intoseparateandconcurrenttasks! Balance–musttrytogetequivalentworkfortasks! Datasplitting–toavoiddatacollisions! Datadependency–synchronizationfordatadependency! Testinganddebugging!4.11!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Amdahl’sLaw Identifiesperformancegainsfromaddingadditionalcorestoanapplicationthathasbothserialandparallelcomponents Sisserialportion Nprocessingcores E.g.,ifapplicationis75%parallel/25%serial movingfrom1to2coresresultsinspeedupof1.6times of2.29timeswith4cores AsNapproachesinfinity,speedupapproaches1/S!Serialportionofanapplicationhasdisproportionateeffectonperformancegainedbyaddingmorecores! Butdoesthelawtakeintoaccountcontemporarymulticoresystems?4.12!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!UserThreadsandKernelThreads Userthreads-managementdonebyuser-levelthreadslibrary Threeprimarythreadlibraries: POSIXPthreads! Win32threads Javathreads Kernelthreads-supportedbytheKernel Examples–virtuallyallgeneralpurposeoperatingsystems,including: Windows Solaris Linux Tru64UNIX MacOSX4.13!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!MultithreadingModels Mustestablisharelationshipbetweenuserthreadsandkernelthreads Threemodels: Many-to-One One-to-One Many-to-Many4.14!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!Many-to-One Manyuser-levelthreadsmappedtosinglekernelthread Onethreadblockingcausesalltoblock Multiplethreadsmaynotruninparallelonmulticoresystembecauseonlyonemayaccessthekernelatatime Fewsystemscurrentlyusethismodel Examples: SolarisGreenThreads! GNUPortableThreads!userthreadkernelthreadk4.15!Silberschatz,GalvinandGagne©2013!OperatingSystemConcepts–9thEdition!One-to-One Eachuser-levelthreadmapstokernelthread Creatingauser-levelthreadcreatesakernelthread Moreconcurrencythanmany-to-one Numberofthre

1 / 43
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功