Concurrent C++ Concurrent Programming With ClassWord下载.docx
- 文档编号:22372245
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:62
- 大小:39.78KB
Concurrent C++ Concurrent Programming With ClassWord下载.docx
《Concurrent C++ Concurrent Programming With ClassWord下载.docx》由会员分享,可在线阅读,更多相关《Concurrent C++ Concurrent Programming With ClassWord下载.docx(62页珍藏版)》请在冰豆网上搜索。
Cmelik,Gehani&
Roome1987]whichprovidesparallel
programmingfacilities,andC++[Stroustrup1986],whichprovidesdataabstractionfacilities.C++does
notprovideparallelprogrammingfacilities,andConcurrentCdoesnotprovidedataabstractionfacilities.
Althoughdataabstractionfacilitiesareimportantforwritingconcurrentprograms,wedidnotprovidethem
inConcurrentCbecausewedidnotwanttoduplicatetheC++researcheffort.Instead,wedecidedthatwe
wouldeventuallyintegrateC++andConcurrentCfacilitiestoproducealanguagewithbothdata
abstractionandparallelprogrammingfacilities:
ConcurrentC++.Thiswasapragmaticdecision.Wefelt
thatitwouldbebetterifConcurrentC++hadthesamedataabstractionasC++becausethiswouldmake
ConcurrentC++upwardcompatiblewithC++andConcurrentC++wouldthenbemoreattractiveforC++
usersinterestedinwritingconcurrentprograms.
Havinggainedexperienceinbothlanguages,wedecidedtomergeC++andConcurrentCtoproduce
ConcurrentC++.Dataabstractionandparallelprogrammingfacilitiesareorthogonal.Despitethis,the
mergerofConcurrentCandC++raisedseveralintegrationissues.Inthispaper,wewillgivebrief
introductionstoC++andConcurrentCandthenpresenttwoexamplesofhowclasses,thedataabstraction
facilityofC++,canbevaluableforwritingconcurrentprograms.Afterthiswewilldiscusstheissuesin
integratingC++andConcurrentCandthendescribethecurrentstateofaffairs.
2.BriefSummaryofC++
TheC++dataabstractionfacilityiscalledtheclass.Classdeclarationsconsistoftwoparts:
aspecification
andabody.Theclassspecificationrepresentstheclass‘‘userinterface’’.Itcontainsalltheinformation
necessaryfortheuserofaclass.Theclassspecificationalsocontainsinformationnecessaryforthe
compilertoallocateclassobjects.Theclassbodyconsistsofbodiesoffunctionsdeclaredintheclass
specificationbutwhosebodieswerenotgiventhere.Intherestofthissection,wewillgiveabrief
overviewoftheC++classfacility.Foradetailedexplanation,seeTheC++ProgrammingLanguage
[Stroustrup1986].
Classspecificationshavetheform
classname{
privatecomponents
publiccomponents
};
Theprivatecomponentsofaclassaredataitemsandfunctionsthatimplementclassobjects.These
representinternaldetailsoftheclassandcannotbeaccessedbytheuserofaclass.
Thepublicclasscomponentscanbedataitems,constructors,destructors,memberfunctions(operators),
andfriendfunctions(operators).Thepubliccomponents(tobeprecise)representtheclassuserinterface.
Thesearethecomponentsthattheuserofaclasscanuseorcall.Constructorsarefunctionsthatarecalled
automaticallytoconstructaclassvalue.Destructorsarealsofunctionsthatarecalledautomaticallywhen
thescopeofaclassobjectisleft;
theyareintendedforperforming‘‘cleanup’’chores.Memberandfriend
functionsarefunctionsthatareusedtomanipulateclassobjects.1Notethatoperatorscanbe‘‘overloaded’’
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
public:
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
-2-
inC++.
Asanexampleofclasses,considertheclasscomplex:
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
classcomplex{
doublere,im;
complex(doubler,doublei);
complex(doubler);
complex();
doublereal();
doubleimag();
friendcomplexoperator+(complex,complex);
friendcomplexoperator-(complex,complex);
friendcomplexoperator-(complex);
friendcomplexoperator*(complex,complex);
friendcomplexoperator/(complex,complex);
friendintoperator==(complex,complex);
friendintoperator!
=(complex,complex);
};
Thefirstthreelinesinthepublicpartofthecomplexclassshownabovearedeclarationsofconstructors.
Anappropriateconstructor,selectedaccordingtotheinitializationvaluessupplied,isautomaticallycalled
whencomplexvariablesaredefined.Thenextlinedeclaresthememberfunctionsrealandimag,and
theremaininglinesdeclarefriendoperators.
Wewillshowthedefinitionsofoneconstructorfunction,onememberfunctionandonefriendoperator.
#include"
complex.h"
complex:
:
complex(doubler,doublei)
{
re=r;
im=i;
}
doublecomplex:
real()
returnre;
complexoperator+(complexa,complexb)
returncomplex(a.re+b.re,a.im+b.im);
}
Herearesomeexamplesillustratingusesofthecomplexclass:
__________________
1.Inthispaper,weshallnotdistinguishbetweenmemberandfriendfunctionsexcepttosaythattheirsyntaxisslightlydifferent.
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
File:
complex.h
-3-
complexa=complex(5.0,6.0),b=complex(1.0,1.0);
c=a+b;
Notethatforillustrationpurposes,variablesaandbhavebeeninitializedexplicitlyandvariablechasnot
beenexplicitlyinitialized.Forvariablesaandb,thefirstconstructorshownisautomaticallyinvokedto
constructtheinitialvalue,andforvariablecthethirdconstructorisinvokedtoconstructthedefaultinitial
value.Theconstructorinvokeddependsupontheinitialargumentssupplied(ornotsupplied)when
definingaclassvariable.
3.BriefSummaryofConcurrentC
AConcurrentCprogramconsistsofasetofcomponents,calledprocesses,thatexecuteinparallel.
ConcurrentCprovidesfacilitiesfordeclaringandcreatingprocesses,processsynchronizationand
interaction,processterminationandabortion,priorityspecificationandwaitingformultipleevents,
amongstotherthings.
ConcurrentCprocessesinteractwitheachotherbymeansoftransactions.Transactionsareassociatedwith
processesandthesemaybethoughtofasservicesthatarecalled(used)byotherprocesses.Processes
callingservicesmaybethoughtofas‘‘client’’processesandprocessesoffering(andaccepting)services
maybethoughtofas‘‘server’’processes.Weshallusetheterms‘‘calling’’and‘‘client’’,andtheterms
‘‘called’’and‘‘server’’processesinterchangeably.Therearetwokindsoftransactions:
synchronous(or
blocking)andasynchronous(ornonblocking).Thecallingprocesssendsinformationtotheserverprocess
bymeansoftransactionparameters,andincaseofsynchronoustransactioncalls,thecalledprocesscan
returninformationtothecallingprocessasthetransactionresult.
Aprocesscallingasynchronoustransactionisblockeduntilthecalledprocessacceptsthetransaction
(givestherequestedservice),executesthecodeassociatedwiththetransaction,andreturnsthetransaction
result,ifany.Synchronoustransactionsallowbidirectionalcommunicationbetweentheinteracting
processes.Synchronoustransactioncallscanalsobeusedforprocesssynchronization:
thecallingand
receivingprocesssynchronizeatthetransactioncall.Theyarefreetoresumeindependentoperationafter
thetransactioncallhasbeenaccepted.Infact,transactioncallscanbeusedjustforsynchronization(a
transactionneednothaveanyparametersanditcanhavethevoidresulttype).
Aprocesscallinganasynchronoustransactionisallowedtocontinueimmediatelyaftermakingthecall.
Thetransactionisacceptedbythecalledpro
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Concurrent C+ Programming With Class
链接地址:https://www.bdocx.com/doc/22372245.html