Paul Licameli
2016-11-05 18:23:27 UTC
Strong and Weak exception safety guarantees. Are we all familiar with such
C++ jargon?
This is pertinent to the discussion of Bug 437, and the careful, thorough
ways of fixing it.
If you have some object, and do a complicated multi-part operation on it,
which may fail at some point, the "strong" guarantee is that the object is
restored to its state as it was before attempting the operation. The
"weak" guarantee is only that the object is left in some unspecified but
consistent state, satisfying its "class-invariant" conditions, so that
further operations on it do not lead to undefined behavior.
I think that to fix Bug 437, for all editing operations that might fail
because of exhaustion of disk space, and without too many error-handling
catch blocks, we might easily provide a strong guarantee by using
Project::RollbackState (something I had occasion to add earlier). This
works by restoring the last state saved in Undo history, without completing
the (failed) operation and pushing a new state.
At lower levels than the Project, such as the WaveTrack or WaveClip, I
think it looks like too much effort to make a strong guarantee: try to
ensure only the weak guarantee. Using RollbackState will destroy the
WaveTrack and WaveClip and Sequence objects holding the partial results of
the failed operation.
This assumes most editing operations that could exhaust memory (I include
effects and generators) can acceptably just be aborted, and then the user
can go free resources and try again.
Recording should still be treated with some extra, special effort to save
as much of the data as possible.
PRL
C++ jargon?
This is pertinent to the discussion of Bug 437, and the careful, thorough
ways of fixing it.
If you have some object, and do a complicated multi-part operation on it,
which may fail at some point, the "strong" guarantee is that the object is
restored to its state as it was before attempting the operation. The
"weak" guarantee is only that the object is left in some unspecified but
consistent state, satisfying its "class-invariant" conditions, so that
further operations on it do not lead to undefined behavior.
I think that to fix Bug 437, for all editing operations that might fail
because of exhaustion of disk space, and without too many error-handling
catch blocks, we might easily provide a strong guarantee by using
Project::RollbackState (something I had occasion to add earlier). This
works by restoring the last state saved in Undo history, without completing
the (failed) operation and pushing a new state.
At lower levels than the Project, such as the WaveTrack or WaveClip, I
think it looks like too much effort to make a strong guarantee: try to
ensure only the weak guarantee. Using RollbackState will destroy the
WaveTrack and WaveClip and Sequence objects holding the partial results of
the failed operation.
This assumes most editing operations that could exhaust memory (I include
effects and generators) can acceptably just be aborted, and then the user
can go free resources and try again.
Recording should still be treated with some extra, special effort to save
as much of the data as possible.
PRL