Developed by HUGHES NETWORK SYSTEMS (HNS) for the benefit of the
ACE community at large A Tutorial Introduction to the ADAPTIVE Communication Environment (ACE)
Umar Syyid (usyyid@hotmail.com)
Acknowledgments I would like to thank the following people for their assistance in making this tutorial possible, Ambreen Ilyas ambreen@bitsmart.com James CE Johnson jcej@lads.com Aaron Valdivia avaldivia@hns.com Douglas C. Schmidt schmidt@cs.wustl.edu Thomas Jordan ace@programmer.net Erik Koerber erik.koerber@siemens.at Martin Krumpolec krumpo@pobox.sk Fred Kuhns fredk@tango.cs.wustl.edu Susan Liebeskind shl@cc.gatech.edu Andy Bellafaire amba@callisto.eci-esyst.com Marina marina@cs.wustl.edu Jean-Paul Genty jpgenty@sesinsud.com Mike Curtis mccurry@my-deja.com Philippe Perrin perrin@enseirb.fr Gunnar Bason a98gunbu@student.his.se
TABLE OF CONTENTS Acknowledgments....................................................................................................................................................0 TABLE OF CONTENTS ........................................................................................................................................... I THE ADAPTIVE COMMUNICATION ENVIRONMENT.................................................................................1 THE ACE ARCHITECTURE.................................................................................................... ...
Developed by HUGHES NETWORK
SYSTEMS (HNS) for the benefit of the
ACE community at large
A Tutorial Introduction to the
ADAPTIVE Communication
Environment (ACE)
Umar Syyid
(usyyid@hotmail.com)
Acknowledgments
I would like to thank the following people for their assistance in making this tutorial possible,
Ambreen Ilyas ambreen@bitsmart.com
James CE Johnson jcej@lads.com
Aaron Valdivia avaldivia@hns.com
Douglas C. Schmidt schmidt@cs.wustl.edu
Thomas Jordan ace@programmer.net
Erik Koerber erik.koerber@siemens.at
Martin Krumpolec krumpo@pobox.sk
Fred Kuhns fredk@tango.cs.wustl.edu
Susan Liebeskind shl@cc.gatech.edu
Andy Bellafaire amba@callisto.eci-esyst.com
Marina marina@cs.wustl.edu
Jean-Paul Genty jpgenty@sesinsud.com
Mike Curtis mccurry@my-deja.com
Philippe Perrin perrin@enseirb.fr
Gunnar Bason a98gunbu@student.his.se
TABLE OF CONTENTS
Acknowledgments....................................................................................................................................................0
TABLE OF CONTENTS ........................................................................................................................................... I
THE ADAPTIVE COMMUNICATION ENVIRONMENT.................................................................................1
THE ACE ARCHITECTURE...........................................................................................................................................2
The OS Adaptation Layer .......................................................................................................................................2
The C++ wrappers layer.........................................................................................................3
The ACE Framework Components ........................................................................................................................4
IPC SAP ..........................................................................................................................................................................6
CATEGORIES OF CLASSES IN IPC SAP.6
THE SOCKETS CLASS CATEGORY (ACE_SOCK) ......................................................................................................7
Using Streams in ACE ............................................................................................................................................8
Using Datagrams in ACE............................12
Using Multicast with ACE ....................................................................................................................................15
MEMORY MANAGEMENT ...................................................................................................................................19
ALLOCATORS .............................................................................................................................................................20
Using the Cached Allocator .................................................................................................................................20
ACE_MALLOC23
How ACE_Malloc works...........................24
Using ACE_Malloc...............................................................................................................................................25
USING THE MALLOC CLASSES WITH THE ALLOCATOR INTERFACE..........................................................................28
THREAD MANAGEMENT .....................................................................................................................................29
CREATING AND CANCELING THREADS ......................................................................................................................29
SYNCHRONIZATION PRIMITIVES IN ACE...................................................................................................................32
The ACE Locks Category .....................................................................................................................................32
Using the Mutex classes....................................................................................................................................................... 33
Using the Lock and Lock Adapter for dynamic binding.................................................................................................... 35
Using Tokens..................................................... 37
The ACE Guards Category...................................................................................................................................38 E Conditions Category.............................................................................................................................40
Miscellaneous Synchronization Classes ..............................................................................................................43
Barriers in ACE .................................................................................................................................................................... 43
Atomic Op............................................................................................................................................................................. 44
THREAD MANAGEMENT WITH THE ACE_THREAD_MANAGER.................................................................................46
THREAD SPECIFIC STORAGE......................................................................................................................................49
TASKS AND ACTIVE OBJECTS...........................................................................................................................52
ACTIVE OBJECTS.........................52
ACE_TASK.................................53
Structure of a Task ................................................................................................................................................53
Creating and using a Task....................................................................................................................................54
Communication between tasks .............................................................................................................................55
THE ACTIVE OBJECT PATTERN..................................................................................................................................58
How the Active Object Pattern Works .................................................................................................................58
I
THE REACTOR ........................................................................................................................................................66
REACTOR COMPONENTS............................................................................................................................................66
EVENT HANDLERS......................67
Registration of Event Handlers ............................................................................................................................70
Removal and lifetime management of Event Handlers .......................................................................................70
Implicit Removal of Event Handlers from the Reactors Internal dispatch tables.............................................................. 71
Explicit removal of Event Handlers from thrs Internal Dispatch Tables........... 71
EVENT HANDLING WITH THE REACTOR....................................................................................................................72
I/O Event De-multiplexing....................................................................................................................................72
TIMERS........................................76
ACE_Time_Value..................................................................................................................................................76
Setting and Removing Timers...............................................................................................................................77
Using different Timer Queues ...................................................................................................78
HANDLING SIGNALS...................................................................................................................................................79
USING NOTIFICATIONS................79
THE ACCEPTOR AND CONNECTOR ................................................................................................................83
THE ACCEPTOR PATTERN.................................................................................................................................84
COMPONENTS ....................................................................................................................................................85
USAGE ..................................................................................................................................................................86
THE CONNECTOR ..................................................................................................................90
USING THE ACCEPTOR AND CONNECTOR TOGETHER ..........................................................................91
ADVANCED SECTIONS................................................................................................................................................93
THE ACE_SVC_HANDLER CLASS ...................................................................................................................94
ACE_Task........................................................................................................................