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 1 commit
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: 24 additions & 0 deletions paddle/framework/channel_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,27 @@ TEST(Channel, UnbufferedLessReceiveMoreSendTest) {
t.join();
delete ch;
}

TEST(Channel, UnbufferedEmptyReceiveSendReceiveTest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that UnbufferedEmptyReceiveSendReceiveTest is similar with UnbufferedMoreReceiveLessSendTest. Is there a redundancy? I'm not sure. @abhinavarora

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(100)); // wait 0.5 sec
EXPECT_EQ(sum_recv, 0U);

ch->Send(&i);

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