Fix a race in async tensor evaluation: Don't run on_done() until after device.deallocate() / evaluator.cleanup() complete, since the device might be destroyed after on_done() runs.

This commit is contained in:
Rasmus Munk Larsen 2019-11-11 12:26:41 -08:00
parent c952b8dfda
commit 0ed0338593

View File

@ -592,8 +592,8 @@ class TensorAsyncExecutor<Expression, ThreadPoolDevice, DoneCallback,
: evaluator(expr, thread_pool), on_done(std::move(done)) {}
~TensorAsyncExecutorContext() {
on_done();
evaluator.cleanup();
on_done();
}
Evaluator evaluator;
@ -674,9 +674,9 @@ class TensorAsyncExecutor<Expression, ThreadPoolDevice, DoneCallback,
on_done(std::move(done)) {}
~TensorAsyncExecutorContext() {
on_done();
device.deallocate(tiling.buffer);
evaluator.cleanup();
on_done();
}
const ThreadPoolDevice& device;
@ -755,9 +755,9 @@ class TensorAsyncExecutor<Expression, ThreadPoolDevice, DoneCallback,
on_done(std::move(done)) {}
~TensorAsyncExecutorContext() {
on_done();
device.deallocate(tiling.buffer);
evaluator.cleanup();
on_done();
}
const ThreadPoolDevice& device;