DOP-C Programming Guide

Multiverses

Sometimes we want our table to be editable by more than one process. Doing this naively however will lead to memory races, which is never good. DOP-C therefore employs the concept of a multiverse. By this, we mean the creation of many versions of a table that can be separately edited. These copies can be collapsed later back into the original.

Creating a Multiverse

In order to create a multiverse, we need a table prototype. This is a class which represents the constituents of our table and how they are initialised. We also need to create an array of these to represent the copies. To see an example of this, see Constructing Tables. The pattern used in the example is used in the example below:

Data::Proto copies[10]; 
dopc::AdditiveMultiverse<Data::Proto> multiverse(&Data::main, 10, copies, 0);

The final argument in the multiverse constructor represents the offset in the Data::Proto class at which to find the dopc::Table. Once we have created a multiverse, each copy can be passed to separate threads quite safely. Note that, as of now, we only have additive multiverses. This means that each thread should not endeavour to remove rows, or sort the tables.

Collapsing the Multiverse

Once each thread is done with its copy, we can apply all additions to the original table.

multiverse.collapse(); 

The original table Data::main should now contain all rows added by each thread.