Skip to content

Commit def655e

Browse files
Roy Lifacebook-github-bot
Roy Li
authored andcommitted
fix critical section of atomic add op
Summary: When testing D10220313, I ran into this bug. Reviewed By: aazzolini Differential Revision: D10224295 fbshipit-source-id: f46d7333612bce437c1ae6c0b0b579fc2a639665
1 parent 8689d8a commit def655e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

caffe2/operators/atomic_ops.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class AtomicFetchAddOp final : public Operator<CPUContext> {
3434
auto& b = Input(2);
3535
auto* c = Output(0);
3636
auto* d = Output(1);
37-
c->Resize(std::vector<int64_t>());
38-
d->Resize(std::vector<int64_t>());
37+
std::lock_guard<std::mutex> lg(*mutex);
38+
c->Resize();
39+
d->Resize();
3940
auto* aPtr = a.data<int32_t>();
4041
auto* bPtr = b.data<int32_t>();
4142
auto* cPtr = c->template mutable_data<int32_t>();
4243
auto* dPtr = d->template mutable_data<int32_t>();
43-
std::lock_guard<std::mutex> lg(*mutex);
4444
*dPtr = *aPtr;
4545
*cPtr = *aPtr + *bPtr;
4646
return true;

0 commit comments

Comments
 (0)