Skip to content

Commit 2f0b63b

Browse files
committed
Oops, this was obviously not thread-safe.
1 parent 1c27357 commit 2f0b63b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

include/react/common/ContinuationInput.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <functional>
1212
#include <memory>
13+
#include <mutex>
1314

1415
#include "tbb/concurrent_vector.h"
1516

@@ -36,8 +37,9 @@ class ContinuationInput
3637
template <typename F>
3738
void Add(F&& input)
3839
{
39-
if (bufferedInputsPtr_ == nullptr)
40-
bufferedInputsPtr_ = std::unique_ptr<InputVectT>(new InputVectT());
40+
std::call_once(bufferedInputsInit_, [this] {
41+
bufferedInputsPtr_.reset(new InputVectT());
42+
});
4143
bufferedInputsPtr_->push_back(std::forward<F>(input));
4244
}
4345

@@ -52,7 +54,8 @@ class ContinuationInput
5254
}
5355

5456
private:
55-
std::unique_ptr<InputVectT> bufferedInputsPtr_ = nullptr;
57+
std::once_flag bufferedInputsInit_;
58+
std::unique_ptr<InputVectT> bufferedInputsPtr_ = nullptr;
5659
};
5760

5861
/****************************************/ REACT_IMPL_END /***************************************/

0 commit comments

Comments
 (0)