摘要 面向对象程序设计模型中的并发行为 摘要 面向对象软件开发技术已广泛应用于软件系统的设计与构造,面向对象模型 是对客观世界活动的自然刻划,其中的对象是对客观世界中有形或无形实体的直 接模拟。用面向对象技术开发软件,能够减小问题域与解题域之间的语义间隙, 使得软件开发过程显得比较自然,从而可提高软件生产率。 客观世界中的活动往往是并发进行的,而目前大多数面向对象模型只提供了 描述系统顺序执行的能力。为了加强面向对象模型的表达能力,必须在面向对象 模型中提供并发描述机制,使其能够描述客观世界中的并发行为。 本论文工作的主要目的就是研究如何在面向对象模型中引进并发描述机制, 使其能够描述客观活动的并发行为,并且,所引进的并发描述机制要与面向对象 模型相容,不破坏面向对象模型中已有的一些特性。 本论文首先分析了在面向对象模型中引进并发所面临的各种问题,并给出了 现有的一些解决方案。然后,在研究了现有的一些并发面向对象模型的基础上, 论文提出了一个基于并发对象的并发面向对象模型,在该模型中,并发机制以一 种与面向对象模型相集成的方式被引进。对象可以有私有执行线程,各对象的私 有线程之间以及对象内部的各线程之间并发执行:对象间采用远程过程调用方式 进行通信,对象对消息的接收以及内部各线程之间的并发执行进行控制:并发对 象类的并发属性可以从父类继承。论文还用CSP对所提模型中并发对象的语义进行 了形式化描述,论文最后用所提模型对C++进行了并发扩充,使得C+能够用于描 述并发计算。 关键词:面向对象,程序设计,并发对象,CSP,C++ i
摘 要 i 面向对象程序设计模型中的并发行为 摘 要 面向对象软件开发技术已广泛应用于软件系统的设计与构造,面向对象模型 是对客观世界活动的自然刻划,其中的对象是对客观世界中有形或无形实体的直 接模拟。用面向对象技术开发软件,能够减小问题域与解题域之间的语义间隙, 使得软件开发过程显得比较自然,从而可提高软件生产率。 客观世界中的活动往往是并发进行的,而目前大多数面向对象模型只提供了 描述系统顺序执行的能力。为了加强面向对象模型的表达能力,必须在面向对象 模型中提供并发描述机制,使其能够描述客观世界中的并发行为。 本论文工作的主要目的就是研究如何在面向对象模型中引进并发描述机制, 使其能够描述客观活动的并发行为,并且,所引进的并发描述机制要与面向对象 模型相容,不破坏面向对象模型中已有的一些特性。 本论文首先分析了在面向对象模型中引进并发所面临的各种问题,并给出了 现有的一些解决方案。然后,在研究了现有的一些并发面向对象模型的基础上, 论文提出了一个基于并发对象的并发面向对象模型,在该模型中,并发机制以一 种与面向对象模型相集成的方式被引进。对象可以有私有执行线程,各对象的私 有线程之间以及对象内部的各线程之间并发执行;对象间采用远程过程调用方式 进行通信,对象对消息的接收以及内部各线程之间的并发执行进行控制;并发对 象类的并发属性可以从父类继承。论文还用CSP对所提模型中并发对象的语义进行 了形式化描述,论文最后用所提模型对C++进行了并发扩充,使得C++能够用于描 述并发计算。 关键词:面向对象,程序设计,并发对象,CSP,C++
Abstract Concurrent Behavior in Object-Oriented Programming Models Abstract Object-oriented(OO)technique has been widely used in the design and construction of software systems.Object-oriented models describe the real world activities in a natural way.The objects in the models are the direct simulations of the entities in the real or mind world.Developing software with OO technique can minimize the semantic gap between problems and solutions.It makes software development processes more natural and,thus, promotes software productivity. The real-world activities are usually carried out concurrently.Currently,OO models only support the specification of the sequential behaviors of a system.To model the concurrent behaviors of the real-world activities,concurrency must be introduced into OO models. The main concern of this dissertation is to study how to introduce concurrency into OO models.The introduced concurrent mechanism should be compatible with OO models and does not hamper the existing properties of OO models. In this dissertation,all kinds of problems encountered in introducing concurrency into OO models are analyzed first.Then,based on the study of some existing concurrent object-oriented models,the dissertation present a concurrent object-oriented model around concurrent objects.In the model,concurrency is introduced in an integrated way. Objects may have private threads.Threads in objects execute concurrently.The remote procedure calls are used as communication mechanism between objects.Objects control their own message accepting and the concurrent executions of their private threads.The specification of concurrency control in a class can be inherited by its subclasses.The formal semantics of the concurrent objects in the presented model has been given in CSP.At last, C++has been extended based on the presented concurrent object-oriented model. Keywords:Object-Oriented,Programming,Concurrent Objects,CSP,C++ ii
Abstract ii Concurrent Behavior in Object-Oriented Programming Models Abstract Object-oriented(OO) technique has been widely used in the design and construction of software systems. Object-oriented models describe the real world activities in a natural way. The objects in the models are the direct simulations of the entities in the real or mind world. Developing software with OO technique can minimize the semantic gap between problems and solutions. It makes software development processes more natural and, thus, promotes software productivity. The real-world activities are usually carried out concurrently. Currently, OO models only support the specification of the sequential behaviors of a system. To model the concurrent behaviors of the real-world activities, concurrency must be introduced into OO models. The main concern of this dissertation is to study how to introduce concurrency into OO models. The introduced concurrent mechanism should be compatible with OO models and does not hamper the existing properties of OO models. In this dissertation, all kinds of problems encountered in introducing concurrency into OO models are analyzed first. Then, based on the study of some existing concurrent object-oriented models, the dissertation present a concurrent object-oriented model around concurrent objects. In the model, concurrency is introduced in an integrated way. Objects may have private threads. Threads in objects execute concurrently. The remote procedure calls are used as communication mechanism between objects. Objects control their own message accepting and the concurrent executions of their private threads. The specification of concurrency control in a class can be inherited by its subclasses. The formal semantics of the concurrent objects in the presented model has been given in CSP. At last, C++ has been extended based on the presented concurrent object-oriented model. Keywords: Object-Oriented, Programming, Concurrent Objects, CSP, C++
目录 目录 第一章前言。 1 1.1面向对象模型 1.1.1对象与消息 1 1.1.2类与继承 2 1.1.3多态和动态定连 …2 1.1.4类型与子类型 2 1.1.5相关的术语 1.2并发与面向对象模型 1.3主要工作 1.4论文安排. 5 第二章在面向对象模型中引进并发 6 2.1并发系统的一般模型 6 2.2面向对象模型的并发执行 8 2.2.1异步消息传递 8 2.2.2主动对象. ..9 2.2.3对象内部并发 9 2.3对象的并发控制…… 。。 11 2.3.1集中控制和分散控制 11 2.3.2隐式控制和显式控制. 12 2.3.3对象并发状态的表示.… 12 2.4并发与继承. 13 2.4.1同步限制、同步代码与同步机制 14 2.4.2继承异常 14 2.5对象与进程. 15 2.6现有系统介绍. 15 2.6.1 Actor模型 16 2.6.2ABCL/1. 17 2.6.3P00L. 19 2.6.4 Hybrid...... 20 2.6.5.DRAGOON 21 试
目 录 iii 目 录 第一章 前言 ......................................................................................................... 1 1.1 面向对象模型......................................................................................... 1 1.1.1 对象与消息.................................................................................. 1 1.1.2 类与继承...................................................................................... 2 1.1.3 多态和动态定连 .......................................................................... 2 1.1.4 类型与子类型 .............................................................................. 2 1.1.5 相关的术语.................................................................................. 3 1.2 并发与面向对象模型 ............................................................................. 3 1.3 主要工作................................................................................................. 4 1.4 论文安排................................................................................................. 5 第二章 在面向对象模型中引进并发................................................................... 6 2.1 并发系统的一般模型 ............................................................................. 6 2.2 面向对象模型的并发执行...................................................................... 8 2.2.1 异步消息传递 .............................................................................. 8 2.2.2 主动对象...................................................................................... 9 2.2.3 对象内部并发 .............................................................................. 9 2.3 对象的并发控制................................................................................... 11 2.3.1 集中控制和分散控制................................................................. 11 2.3.2 隐式控制和显式控制................................................................. 12 2.3.3 对象并发状态的表示................................................................. 12 2.4 并发与继承........................................................................................... 13 2.4.1 同步限制、同步代码与同步机制 ............................................. 14 2.4.2 继承异常.................................................................................... 14 2.5 对象与进程........................................................................................... 15 2.6 现有系统介绍....................................................................................... 15 2.6.1 Actor 模型.................................................................................. 16 2.6.2 ABCL/1 ...................................................................................... 17 2.6.3 POOL ......................................................................................... 19 2.6.4 Hybrid......................................................................................... 20 2.6.5. DRAGOON ............................................................................... 21
目录 2.6.6ACT++ 21 2.6.7 Smalltalk ConcurrentSmalltalk 22 2.6.8 Eiffel、Eiffel/和CEiffel 25 2.7小结. 30 第三章基于并发对象的并发面向对象模型 31 3.1对象系统的并发执行 31 3.1.1对象的私有执行线程 31 3.1.2对象内部的并发 33 3.1.3对象的自治性 33 3.2对象间的通信… 34 3.2.1远程过程调用 34 3.2.2对象的通信对象 35 3.3对象的并发控制, 4… 36 3.3.1条件同步与互斥 36 3.3.2缺省并发控制 37 3.3.3内部并发控制 38 3.4并发对象类的继承 40 3.4.1条件同步控制的继承。 40 3.4.2内部并发控制的继承 40 3.5实例 41 3.6与相关工作的比较.. 47 3.7小结 48 第四章并发对象的形式语义 50 4.1CSP简介… 50 4.2并发对象的定义 51 4.3并发对象的CSP语义 52 4.3.1对象的进程模型 52 4.3.2对象各进程的CSP表示 53 4.3.3消息传递语义 55 4.4小结 56 第五章NDC++:C++的并发扩充 57 iv
目 录 iv 2.6.6 ACT++ ....................................................................................... 21 2.6.7 Smalltalk 和 ConcurrentSmalltalk................................................ 22 2.6.8 Eiffel、Eiffel//和 CEiffel ............................................................. 25 2.7 小结 ...................................................................................................... 30 第三章 基于并发对象的并发面向对象模型 ..................................................... 31 3.1 对象系统的并发执行 ........................................................................... 31 3.1.1 对象的私有执行线程................................................................. 31 3.1.2 对象内部的并发 ........................................................................ 33 3.1.3 对象的自治性 ............................................................................ 33 3.2 对象间的通信....................................................................................... 34 3.2.1 远程过程调用 ............................................................................ 34 3.2.2 对象的通信对象 ........................................................................ 35 3.3 对象的并发控制................................................................................... 36 3.3.1 条件同步与互斥 ........................................................................ 36 3.3.2 缺省并发控制 ............................................................................ 37 3.3.3 内部并发控制 ............................................................................ 38 3.4 并发对象类的继承............................................................................... 40 3.4.1 条件同步控制的继承................................................................. 40 3.4.2 内部并发控制的继承................................................................. 40 3.5 实例 ...................................................................................................... 41 3.6 与相关工作的比较............................................................................... 47 3.7 小结 ...................................................................................................... 48 第四章 并发对象的形式语义 ............................................................................ 50 4.1 CSP 简介............................................................................................... 50 4.2 并发对象的定义................................................................................... 51 4.3 并发对象的 CSP 语义........................................................................... 52 4.3.1 对象的进程模型 ........................................................................ 52 4.3.2 对象各进程的 CSP 表示............................................................ 53 4.3.3 消息传递语义 ............................................................................ 55 4.4 小结 ...................................................................................................... 56 第五章 NDC++ : C++的并发扩充 ..................................................................... 57
目录 5.1预定义的Concurrency类 57 5.2语言扩充 59 5.2.1条件同步定义concurrency_control 60 5.2.2私有线程定义threads.. 61 5.2.3并发对象类的继承原则 62 5.3转换机制 63 5.3.1成员函数的转换 63 5.3.2私有线程的转换 65 5.3.3初始线程的自动执行 66 5.3.4C+类的转换 67 5.4 Concurrency类的实现 67 5.4.1lock0与unlock0的实现 67 5.4.2 new thread0和stop_threads(0的实现 68 5.4.3与消息有关的函数的实现 69 5.5NDC++的支撑环境 69 5.6小结 70 第六章结束语 71 6.1论文的主要贡献和特色 71 6.2进一步工作」 72 致谢. 73 作者在博士生期间发表(包括已录用)的论文 74 参考文献 75 附录:NDC+扩充语法 81
目 录 v 5.1 预定义的 Concurrency类 ..................................................................... 57 5.2 语言扩充............................................................................................... 59 5.2.1 条件同步定义 concurrency_control............................................ 60 5.2.2 私有线程定义 threads................................................................ 61 5.2.3 并发对象类的继承原则............................................................. 62 5.3 转换机制............................................................................................... 63 5.3.1 成员函数的转换......................................................................... 63 5.3.2 私有线程的转换......................................................................... 65 5.3.3 初始线程的自动执行................................................................. 66 5.3.4 C++类的转换............................................................................. 67 5.4 Concurrency类的实现.......................................................................... 67 5.4.1 lock()与 unlock()的实现............................................................. 67 5.4.2 new_thread()和 stop_threads()的实现 ........................................ 68 5.4.3 与消息有关的函数的实现......................................................... 69 5.5 NDC++的支撑环境 .............................................................................. 69 5.6 小结 ...................................................................................................... 70 第六章 结束语 ................................................................................................... 71 6.1 论文的主要贡献和特色 ....................................................................... 71 6.2 进一步工作........................................................................................... 72 致 谢............................................................................................................... 73 作者在博士生期间发表(包括已录用)的论文.................................................... 74 参考文献............................................................................................................ 75 附录:NDC++扩充语法.................................................................................... 81