ѧ
JOURNAL OF SOFTWARE
2000Vol.11No.4P.494-501




Ada-I:ֱ֧̳еAda95
½Ρ¶濡
ժҪ󲢷ܹԱд,Ӷֺô.Ȼڼ̳쳣ĴڣӰ˲̳.Ada95ֲ֧Ƶ֮һ,ֱ֧ļ̳.Ada-IAda95ԵĻϽ,Ӷֱ֧ļ̳,ұ˼̳쳣ĳ.
ؼʡAda95,,̳,̳쳣,󲢷.
ͼšTP312
Ada-I: An Extension Language Supporting Inheritance of Protected Objects Based on Ada95
LU JiaWEN Dong-chanWANG Ding-xing
Department of Computer Science and TechnologyTsinghua UniversityBeijing100084
AbstractObject-Oriented concurrent languages can help programmers to develop concurrent programs and to gain benefits by using object-oriented technology, such as encapsulation and inheritance. But inheritance anomaly influences designing object-oriented concurrent languages. Ada95 is one of the object-oriented languages that support concurrent program designing, but it does not support the inheritance of protected objects. Ada-I language based on Ada95 supports the inheritance of protected objects, and can avoid the inheritance anomaly.
Key wordsAda95, protected object, inheritance, inheritance anomaly, object-oriented concurrent language.
Ŀǰ,ڼѧĸзǳ㷺Ӧ,󲢷,ABCL/1,Presto,ACT++ȵ.ڼ̳쳣(inheritance anomaly),һЩ󲢷Բܺܺõִ֧븴,ƻ˶ļ̳.Ը,ѧ˽14.
Ada95ֲ֧ҹ㷺Ӧõĸ߼֮һ.(task),(protected),Լһϵֲ֧Ƶ﷨.Ada95,ͱΪλ,ͨͱĲЭͬĳһضļʹ.ǽAda95еͱͳһΪ.
ȻAda95Ѿ˳ƷӦƵҪ,ּ֧̳С̬װȵ,ڲƷ棬Ada95еĲҲһЩ,װ,,Ada95ֲ֧ļ̳,ˣAda95󲢷ƵҪ.
ΪAda95еĶܲϴ,֮ͨݹ,еĶֻͨϢݽ׳зĸ.Ada95еıеĶ,Ƚ̳е.ˣڱҪ۱ļ̳.
ڱ,ǻAda95һֱ֧̳еAda-I,ڸ˼̳쳣.
1̳쳣
̳ƵĹؼ֮һ,˳н븴ĳ÷.ǰ,ȻԺܷ뵽,󲢷,Ǽ̳ȴܰ˳еʹ÷򵥵벢,Ϊᵼ¼̳쳣ĳ,Ҳ˵಻ܽʽ,Ҳֻвеı,ı̳еĸнд븴,.ּ̳쳣ʱ,಻Ҫв߱ı,ҲòԸжĳЩ,з¶.
󲢷ϵͳ,ڿͬʱжϢһ,֮Ϣݾвȷ,ԣΪ˱֤ԺͲݵһ,ÿԽյϢͨ顢ӦԼкӦ״̬ת3.ĵǰ״̬Ϣʱ,򲻴Ϣ,ֱ״̬ϢΪֹ.ĳϢĲ״̬ΪϢĿ״̬(acceptable states).ϢĿ״̬ܺͳΪòĿ״̬.
MatsuokaYonezawaף1з˲̳쳣ֵԭ,Ϊ̳쳣ĳΪڼ̳и󷽷ʱӵ·ı˸Ŀ״̬,Ϊ봦״̬ص״̬תǺͶķص,ӶҪ¸дķ,µ״̬תҪ.ף1ݽ״̬ĸıֳ3ࣺ(1) ״̬»֣(2) ״̬ʷأ(3) ״̬޸.
,C++󲢷ԶԼ̳쳣ֵԭһ򵥽.
1.1״̬»
ÿпԿΪһϵе״̬ת,ÿһ״̬ɲбǰȡֵɵ.ǿԸݲÿһĿɽ,ҲӦϢĿ״̬,γɿ״̬һ.
нBufferΪ,н,get()ӶȡһԪ,put(x)Ԫx.Ȼ,ԪظΪ0,пʱ,get(),ʱ,put(x).,ǿԵõнп״̬һ֣empty,partial,full,ӦΪпաа.
ǽнBufferΪ,һµSubBuffer.ڸ,һµķget2(),ӶȡԪ.ȻԪظΪ1ʱ,get2(),get(),put(x)Ȼܹ.ǿԿSubBufferĿ״̬븸Bufferȶһget2()Ŀ״̬one,ˣSubBufferԸĿ״̬µĻ֣empty,one,partial,fullͼ1ʾ.

Fig.1Repartition of acceptable states set
ͼ1״̬»
ǿԿ,SubBufferд˸еķ,ֱӼ̳.ͳ˼̳쳣.
1.2״̬ʷ
״̬ʷָ·븸෽еĴ.,нBufferΪһNewBuffer.һµķgget(),֮ǰput(x).
ͼ2ʾ,Ϊgget()Ŀ״̬,Ҫеget(),put(x)ȷ,Ӷ³ּ̳쳣.

Fig.2History relation of acceptable states set
ͼ2״̬ʷ
1.3״̬޸
SubBuffer,û޸ĸĿ״̬,ֻǸı˿״̬Ļ.ҪӻBufferһµLockBuffer,һµǷ.ѾĻ,get(),put(x)Уûм,.,get()put(x)Ŀ,Ҳ˵ӦĿ״̬.
Ϊǲúͼ1ͼ2ͬ,ּ̳쳣.Ϊ˵,ǲµ,ͼ3ʾ.,ķҪ¶,˼̳쳣.

Fig.3Modification of acceptable states set
ͼ3״̬޸
ǿԿ,ͬ,ּ̳쳣ԭҲǲͬ.
2
Ada95ӵԳɷ,רΪĲ.ĽṹĽṹ,е˵岻ͬ.˵ָȨ,ʵֵϸ.һ,岻˵κݣֻ˵ӳʵ.ݱ˽в˵.
ɱ.뱣֮Ĺϵеʵͬ.ĲΪӳͱ,ӳַΪ̺ͺ.̡ڷֱɹؼprocedure,functionentry˵.̿ⷽʽ˽,ֻܶ˽,ڿ˽,,ֻ£Ӧ.
3ǵԷ
Ada95˳Ʒ֧,ּ֧̳С̬װȵ͵.ڲƷ,Ada95ȫ֧.󡢱ַ֧װ,ּ֧̳.ڱ͵,磬ݵ˽СֲĶ.,Ada95ԵĻ,Աּ֧̳е,Ada-IԣĻ,˼̳쳣.
3.1
Ada-IеıAda95е,˵幹.˵͵Ŀɵòڲ.ľʵ.
Ϳ.ΪʹAda-IԼ׶,ֵ֧̳,ֶ֧̳.ʹӸм̳и͵ıͲ.ֻ岻ͬڸ͵ЩͲ,һ棬ͿӸûеıͲ,һ,ͻ¶常͵ıͲ.
˵вùؼinherit˵Ǵĳ.ͬʱ˵ûеıͲ,ԼҪ¶Ĳ.
͵˵ἰĲľʵм.
£
protected type ͱʶ inherit ͱʶ is ˵
δĲ
¶ĸв
...
private
δݡ
...
end ͱʶ
3.2Ͳ
Ada95ԭıͼ3е,˻ᵼ¼̳쳣ķ.Ϊ̳쳣,ǽı䱣ԭ.
ΪеĹ̲ڲһ,ߵĲڹ̲û,ڲҪǰ,ԣòڲ̲.ǣAda-Iбк.
ͬʱ,ǽԭڲֳ֣Ͳж.Ada-Iзֱùؼcondition,action˵.ǿԽconditionactionɱڲ.conditionһʽ,actionһϵж.
Ada-IбڲĻṹ£
entry ʶ () is
begin
condition
begin
ʽ
end condition;
action
begin
ж
end action
end;
Ada-Iеıڱʱ,ȼʽ,ʽΪ,ִactionж,ڵŶӵȴ.еconditionȱʡ.ConditionȱʡʾΪ,Ҳǲ.ȱʡconditionڲ൱Ada95еĹ̲.
Ada-IбĺAda95еһ,û,Ҷ֮Բ.
нΪ,ͼ4ʾ.

Fig.4Bounded buffer
ͼ4н
3.3븴
Ϊʵֲĸ,ǿͲֱø͵Ĳ.,ͲͲϵĹؼsuper,Աʾ.
Superؼֿĳһڲcondition,Ҳaction.ʾ͵ڲconditionactionзֱ̳ӦĸڲӦ.
conditionʹ,£
super.Ͳʶ'condition
actionʹ,£
super.Ͳʶ'action
conditionʹñʾ̳иĳڲconditionʽ,,ñʽʽһĲ,Խ롢򡢷,ֱand,or,notʾ.
actionʹñʾ̳иĳڲaction.
,¶һڲ,Ҫconditionactionֶ˵.ȱʡconditionactionеһ֣ʾӦִӸм̳.
нBufferLockBufferΪ.һǷlockͿunlock.бʱ,getputܲ,ֱб.ͼ5ʾ,LockBufferconditionвsuper.getsuper.putֱʾBuffergetputʽ,дgetput,ȱʡaction˶Ը͵Ķ븴.

Fig.5Locked bounded buffer
ͼ5н
ǿԿ,Ada-I,Ϳ޶ȵؼ̳иеĲ,Ҫ¶常͵Ĳ.
3.4̳쳣
ڵ1ڷ˳ּ̳쳣3ԭ.Ada-IЧЩԭļ̳쳣,Ӷߴ븴õЧ.
ΪAda-I,Ĵ뱻Ϊ֣conditionactionֿԷֱд븴,ǰ仯ļ̳쳣󶼿ͨ¶еconditionֵԽ,¶Ķ.
״̬»ֺͿ״̬޸Ķڸ෽е仯,ˣͼ5ʾ,Ada-Iп״̬޸ļ̳쳣.ͼ6ʾ,ǿ״̬»ļ̳쳣.ڿ״̬ʷļ̳쳣,ͼ6ʾ,ǿԽвactionֳַ.1ͨsuperøͲ,2±д.,ǿԸøвconditionִactionִ,ٽЩдһ.

Fig.6Bounded buffer for get2
ͼ6get2н

Fig.7New bounded buffer 
ͼ7н
ļ򵥷ǿԿ,Ada-Iеı()̳п̳쳣,˵޶ȵؽд븴.
4С
󲢷ܹԱд,Ӷֺô.Ȼڼ̳쳣ĴڣӰ˲̳.
Ada95ֲ֧Ƶ֮һ,ֱ֧ļ̳.Ada95ԵĻAda-I.ֱ֧ļ̳,ұ˼̳쳣ĳ.
Ada-IԽ͵ڲΪж.Ϊڲԣм.ΪԱṩõֶԽ󲢷.
½Σ廪ѧѧ뼼ϵ100084
¶濣廪ѧѧ뼼ϵ100084
ˣ廪ѧѧ뼼ϵ100084
ο
1Matsuoka S, Yonezawa A. Analysis of inheritance anomaly in object-oriented concurrent languages. In: Agha G, Wegner P, Yonezawa A eds. Research Directions in Concurrent Object-Oriented Programming. Cambridge, MA: MIT Press, 1993. 107150
2Neusius C. Synchronizing actions. In: America P ed. Proceedings of the ECOOP'91. Berlin: Springer-Verlag, 1991. 118132
3Meseguer Jos. Solving the inheritance anomaly in concurrent object-oriented programming. In: Nierstrasz O ed. Proceedings of the ECOOP'93. Berlin: Springer-Verlag, 1993. 220246
4Frolund S. Inheritance of synchronization constraints in concurrent object-oriented programming languages. In: Madsen O ed. Proceedings of the ECOOP'92. Berlin: Springer-Verlag, 1992. 185196
