Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block when channel empty, successfully transfer when there is a send #8063

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion paddle/framework/channel_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,36 @@ TEST(Channel, UnbufferedLessReceiveMoreSendTest) {
ch->Receive(&recv);
EXPECT_EQ(recv, i);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait 0.5 sec
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait 0.5 sec
EXPECT_EQ(sum_send, 3U);

CloseChannel(ch);
t.join();
delete ch;
}

TEST(Channel, UnbufferedEmptyReceiveSendReceiveTest) {
auto ch = MakeChannel<int>(0);
unsigned sum_recv = 0;
int i = 10;
// Receive should block initially since channel is
// empty. Once the main thread sends something, it
// should successfully receive and update the sum
std::thread t([&]() {
int recv;
ch->Receive(&recv); // should block the first time
EXPECT_EQ(recv, i);
sum_recv += recv;
});
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // wait 0.5 sec
EXPECT_EQ(sum_recv, 0U);

ch->Send(&i);

CloseChannel(ch);
t.join();
EXPECT_EQ(sum_recv, 10U);

TEST(Channel, UnbufferedMoreReceiveLessSendTest) {
auto ch = MakeChannel<int>(0);
unsigned sum_send = 0;
Expand Down