Commit 32fba02f authored by Antti Soininen's avatar Antti Soininen
Browse files

Prevent a thread from returning an unupdated isCommonBinsFlag

Use lock in MatrixWorkspace::isCommonBins() to stop a thread returning
the cached isCommonBinsFlag while another thread may still be updating
its value.

Re #24292
parent 97dd2740
......@@ -596,6 +596,8 @@ private:
mutable std::atomic<bool> m_isCommonBinsFlagValid{false};
/// Flag indicating whether the data has common bins
mutable bool m_isCommonBinsFlag{false};
/// A mutex protecting the update of m_isCommonBinsFlag.
mutable std::mutex m_isCommonBinsMutex;
/// The set of masked bins in a map keyed on workspace index
std::map<int64_t, MaskList> m_masks;
......
......@@ -961,6 +961,7 @@ bool MatrixWorkspace::isHistogramData() const {
* @return whether the workspace contains common X bins
*/
bool MatrixWorkspace::isCommonBins() const {
std::lock_guard<std::mutex> lock{m_isCommonBinsMutex};
const bool isFlagValid{m_isCommonBinsFlagValid.exchange(true)};
if (isFlagValid) {
return m_isCommonBinsFlag;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment