Skip to content

Commit 239a838

Browse files
authored
Fix VarHandle return bug. (#13354)
1 parent 7c87308 commit 239a838

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

paddle/fluid/operators/distributed/request_handler.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class VarHandle {
5656
const std::string& name,
5757
const platform::DeviceContext* p_ctx = nullptr,
5858
const framework::Scope* p_scope = nullptr)
59-
: ok_(kVarHandleDefaultState) {
59+
: status_(kDefaultState) {
6060
ep_ = ep;
6161
ctx_ = p_ctx;
6262
scope_ = p_scope;
@@ -68,27 +68,29 @@ class VarHandle {
6868

6969
public:
7070
bool Wait() {
71+
int ret = kDefaultState;
7172
{
7273
std::unique_lock<std::mutex> lk(sync_mutex_);
73-
wait_cond_.wait(lk, [this] { return ok_ != kVarHandleDefaultState; });
74+
wait_cond_.wait(lk, [this] { return status_ != kDefaultState; });
75+
ret = status_;
7476
}
75-
VLOG(7) << "VarHandle wait:" << ok_;
76-
return ok_ != 0;
77+
VLOG(7) << "VarHandle wait:" << ret;
78+
return ret != kErrorState;
7779
}
7880

7981
void Finish(bool ok) {
8082
{
8183
std::unique_lock<std::mutex> lk(sync_mutex_);
82-
ok_ = ok;
84+
status_ = ok ? kFinishState : kErrorState;
8385
}
8486
VLOG(7) << "VarHandle finish:" << ok;
8587
wait_cond_.notify_all();
8688
}
8789

8890
std::string String() const {
8991
std::ostringstream s;
90-
s << method_ << " name:[" << name_ << "], ep:[" << ep_ << "], ok:[" << ok_
91-
<< "]";
92+
s << method_ << " name:[" << name_ << "], ep:[" << ep_ << "], status:["
93+
<< status_ << "]";
9294
return s.str();
9395
}
9496

@@ -111,9 +113,13 @@ class VarHandle {
111113
protected:
112114
std::mutex sync_mutex_;
113115
std::condition_variable wait_cond_;
114-
int ok_;
115116

116-
static const int kVarHandleDefaultState = -1;
117+
enum VarHandleStatus {
118+
kDefaultState = -1,
119+
kErrorState = 0,
120+
kFinishState = 1,
121+
};
122+
VarHandleStatus status_;
117123

118124
private:
119125
DISABLE_COPY_AND_ASSIGN(VarHandle);

0 commit comments

Comments
 (0)