-
Notifications
You must be signed in to change notification settings - Fork 14
Util_Concurrent_Arrays
The Util.Concurrent.Arrays generic package defines an array which provides a concurrent read only access and a protected exclusive write access. This implementation is intended to be used in applications that have to frequently iterate over the array content. Adding or removing elements in the array is assumed to be a not so frequent operation. Based on these assumptions, updating the array is implemented by using the copy on write design pattern. Read access is provided through a reference object that can be shared by multiple readers.
The package must be instantiated using the element type representing the array element.
package My_Array is new Util.Concurrent.Arrays (Element_Type => Integer);
The vector instance is declared and elements are added as follows:
C : My_Array.Vector;
C.Append (E1);
To read and iterate over the vector, a task will get a reference to the vector array and it will iterate over it. The reference will be held until the reference object is finalized. While doing so, if another task updates the vector, a new vector array will be associated with the vector instance (but this will not change the reader's references).
R : My_Array.Ref := C.Get;
R.Iterate (Process'Access);
...
R.Iterate (Process'Access);
In the above example, the two Iterate
operations will iterate over the same list of
elements, even if another task appends an element in the middle.
Notes:
-
This package is close to the Java class
java.util.concurrent.CopyOnWriteArrayList
. -
The package implements voluntarily a very small subset of
Ada.Containers.Vectors
. -
The implementation does not use the Ada container for performance and size reasons.
-
The
Iterate
andReverse_Iterate
operation give a direct access to the element.
Generated by Dynamo from util-concurrent-arrays.ads