diff --git a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp index 4a51006..a4448f6 100644 --- a/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp +++ b/stimBuffApis/livoxGen1/ioUringAssemblyEngine.cpp @@ -418,6 +418,23 @@ public: // Check if timer was cancelled (ignore if operation_aborted) if (error == boost::asio::error::operation_aborted) { return; } + /** EXPLANATION: + * This lock acquisition here will also cover the call to + * assembleFrameReq3 below. Because of that, it means that the + * requirement that the lock be held while accessing + * the metadata that's destroyed in stop() is satisfied. + * + * In theory though, we shouldn't need to hold the lock into + * assembleFrameReq3 below because that function doesn't really access + * any state that's destroyed in stop()? But I'm not sure, and we have + * indeed seen a SEGFAULT even in the current code with locking, so + * I'm going to hold the lock here for now. + */ + SpinLock::Guard lock(context->engine.isAssemblingLock); + + if (!context->engine.isAssembling) + { return; } + // Set timer fired flag context->timerFired.store(true); context->assembleFrameReq3(context);