samedi 19 septembre 2020

C++ Destruction with Concurrency

I was reading through Dynamic Initialization and Destruction with Concurrency and below is the implementation regarding destruction order:

• Define a static-duration object that lists pending destructions for groups of declaration-ordered objects. Call this list the declaration-destructor list.

• Define a static-duration object that lists pending destructions for execution-ordered objects not initialized in the context of a declaration-ordered initialization. Call this list the execution-destructor list.

• Define a thread-duration object that lists pending destructions. Call this list the threaded-destructor list.

• When starting initialization of a group of relatively-ordered objects, create an empty threaded-destructor list. The set of static-duration object initializations executed within the dynamic scope of the initializations of this group of objects is called an initialization region.

• For each dynamic initialization within an initialization region, non-atomically insert the destruction at the head of the threaded-destructor list. This list will capture the function-local objects initialized as a consequence of the initialization of non-local objects. The code can be as simple as an insertion onto a singly-linked list with nodes statically allocated.

• When finishing an initialization region, atomically move the threaded-destructor list to the declaration-destructor list as a group. The code can be as simple as an atomic insertion onto a singly-linked list with nodes statically allocated. The atomic insertion can be done with a compare-and-swap-with-release loop, which will terminate rapidly. A read-acquire on the head of the loop will be necessary before traversing the list.

• For each dynamic initialization not within an initialization region, atomically insert the destruction at the head of the execution-destructor list. The code can be as simple as an atomic insertion onto a singly-linked list with nodes statically allocated. The insertion has the same basic algorithm as above.

• Upon program exit, iterate over the execution-destructor list and call the corresponding destructors. After those complete, iterate over the declaration-destructor list and start the corresponding group destruction concurrently. Within each group, iterate sequentially over the destructor list.

Can anyone please provide some examples to understand this theoretical concept?

Aucun commentaire:

Enregistrer un commentaire