Here are some more options.
1. Splicing
Instead of deleting an element, the modifier code can move it to a temporary list using the splice method. Combining one element is a constant time operation. And this does not invalidate any iterators or references (even for the moved item).
Before moving an item, the “modification” code must advance the main copy of the list iterator (belonging to the “iterating” code).
The iterating code should simply clear this temporary list after each iteration.
Advantages: no need to add any flags to containing elements.
Disadvantages: some performance hit due to the need to clear the temporary list; an external interface is needed to promote an iterator belonging to the "iterating" code; if any code between the "iterative" and "modifying" codes should check the next / previous elements with respect to the "remove" element, it sees only the other "deleted" elements, and not the rest.
2. Connect to the blocked flag
If you set the “blocked” flag for an element that is currently specified by an iterator, the “modifying” code can use splicing only for this single element and delete others in the usual way.
The iterative code should just clear the temporary list after each iteration.
Advantages: virtually no performance.
Disadvantages: it is necessary to change the list items; an external interface is needed to promote an iterator belonging to the "iterating" code; if any code between "iterative" and "modifying" codes should check the next / previous elements with respect to the "remove" element, it does not find anything.
3. Flags "Locked" and "Remove"
If you set the “blocked” flag for the element that the iterator currently indicates, the “modifying” code can simply set the “delete” flag for this single element and delete the others in the usual way.
The iteration code should (after each iteration) simply delete the item marked for deletion.
Advantages: virtually no performance; if some code between the "iterating" and "modifying" codes should check the next / previous elements against the "remove" element, it works as expected.
Disadvantages: it is necessary to change the list items.