Synchronization Aspect
[Synchronization Group]

This aspect is defined in file: ../../AspectXLib/RealTime/Synchronization/aspects/Synchronization.ax

Aspect Description

This aspect inserts synchronization code that provides protection against simultaneous access to a class method. Synchronization code is code that protects access to certain code segments. In this example synchronization code provides protection against simultaneous access to a class method by more than one thread of execution. The aspect adds synchronization code to the body of the method that has to be protected. It uses the mutex object to lock the access to the method.

The base code upon which the aspect operates is a small but self-contained application. The application consists of: one main class that holds the main program; two task classes (Task1 and Task2) that represent two threads competing for a shared resource; one resource class (UniqueResource) that represents the shared resource; one helper class (MicroTime) that encapsulates access to timing services.

The aspect transformation adds synchronization code to method activate in class UniqueResource. The woven code calls a system function to acquire the mutex object as soon as the method is entered and releases it when the method is exited.

The activation code uses synchronization primitives provided by the POSIX standard.
Author:
A. Pasetti, O. Rohlik
See also:
Entry

Pointcuts

classtargetClassDeclaration
  Points to the target class declaration
unittargetClassUnit
  Points to the unit where is declared class identified by pointcut targetTaskClassDeclaration
functiontargetSynchronizedFunction
  Point to the definition of function that has to be synchronized
constructortargetConstructorImplementation
  Points to all constructors of the target class

Advices

addaddMutexDeclaraion
  Add declaration of the mutex object to the class declaration
addaddInclude
  Add the #include <pthread
begininitializeMutex
  Adds the initialization of the mutex variable to the constructor
beginatBegin
  Inserts the code that locks the access to the method body by acquiring the mutex
endatEnd
  Inserts the code that release the access to the method body by releasing the mutex

Pointcut Documentation

class targetClassDeclaration (source)
Points to the target class declaration. The class is identified by its full name: UniqueResource.
unit targetClassUnit (source)
Points to the unit where is declared class identified by pointcut targetTaskClassDeclaration.
function targetSynchronizedFunction (source)
Point to the definition of function that has to be synchronized. The function is identified by its full name: UniqueResource::activate()
constructor targetConstructorImplementation (source)
Points to all constructors of the target class. Constructors are identified by name. Constructor names consists of two name subelements. Only the first subelement is used in this pointcut. However the full name can be also used to constraint the pointcut: src:name='UniqueResource::UniqueResource'.

Advice Documentation

add addMutexDeclaraion (source)

Triplet: class add declaration

Add declaration of the mutex object to the class declaration. It is declared as private since it is only used in the activate() method to protect it against access by more than one thread.

Refers to global pointcut: class targetClassDeclaration

add addInclude (source)

Triplet: unit add include

Add the #include <pthread.h> preprocessor instruction. Header file pthread.h contain declaration of methods and data types implementing mutual exclusive access policy according to the POSIX standard.

Refers to global pointcut: unit targetClassUnit

begin initializeMutex (source)

Triplet: constructor begin codeFragment

Adds the initialization of the mutex variable to the constructor. The mutex variable has to be initialized prior its first use.

Refers to global pointcut: constructor targetConstructorImplementation

begin atBegin (source)

Triplet: function begin codeFragment

Inserts the code that locks the access to the method body by acquiring the mutex. The code is inserted at the very beginning of the target method.

Refers to global pointcut: function targetSynchronizedFunction

end atEnd (source)

Triplet: function end codeFragment

Inserts the code that release the access to the method body by releasing the mutex. The code is inserted at the very end of the target method.

Refers to global pointcut: function targetSynchronizedFunction