提交 56ebb76c 编写于 作者: C chengduoZH

add the properties of buffered channel and unbuffered channel

上级 d2a31fb8
...@@ -149,7 +149,7 @@ void ChannelCloseUnblocksReceiversTest(Channel<int> *ch) { ...@@ -149,7 +149,7 @@ void ChannelCloseUnblocksReceiversTest(Channel<int> *ch) {
std::thread t[num_threads]; std::thread t[num_threads];
bool thread_ended[num_threads]; bool thread_ended[num_threads];
// Launches threads that try to read and are blocked becausew of no writers // Launches threads that try to read and are blocked because of no writers
for (size_t i = 0; i < num_threads; i++) { for (size_t i = 0; i < num_threads; i++) {
thread_ended[i] = false; thread_ended[i] = false;
t[i] = std::thread( t[i] = std::thread(
...@@ -167,7 +167,7 @@ void ChannelCloseUnblocksReceiversTest(Channel<int> *ch) { ...@@ -167,7 +167,7 @@ void ChannelCloseUnblocksReceiversTest(Channel<int> *ch) {
EXPECT_EQ(thread_ended[i], false); EXPECT_EQ(thread_ended[i], false);
} }
// Explicitly close the thread // Explicitly close the channel
// This should unblock all receivers // This should unblock all receivers
CloseChannel(ch); CloseChannel(ch);
......
...@@ -27,11 +27,12 @@ namespace details { ...@@ -27,11 +27,12 @@ namespace details {
// Four of the properties of Buffered Channel: // Four of the properties of Buffered Channel:
// - A send to a full channel blocks temporarily until a receive from the // - A send to a full channel blocks temporarily until a receive from the
// channel or the channel is closed // channel or the channel is closed.
// - A receive from an empty channel blocks temporarily until a send to the // - A receive from an empty channel blocks temporarily until a send to the
// channel or the channel is closed // channel or the channel is closed.
// - A send to a closed channel returns false immediately // - A send to a closed channel returns false immediately.
// - A receive from a closed channel returns false immediately // - A receive from a closed channel returns false immediately.
template <typename T> template <typename T>
class Buffered : public paddle::framework::Channel<T> { class Buffered : public paddle::framework::Channel<T> {
friend Channel<T>* paddle::framework::MakeChannel<T>(size_t); friend Channel<T>* paddle::framework::MakeChannel<T>(size_t);
......
...@@ -23,6 +23,13 @@ namespace paddle { ...@@ -23,6 +23,13 @@ namespace paddle {
namespace framework { namespace framework {
namespace details { namespace details {
// Four of the properties of UnBuffered Channel:
// - A send to a channel blocks temporarily until a receive from the
// channel or the channel is closed.
// - A receive from a channel blocks temporarily until a send to the
// channel or the channel is closed.
// - A send to a closed channel returns false immediately.
// - A receive from a closed channel returns false immediately.
template <typename T> template <typename T>
class UnBuffered : public paddle::framework::Channel<T> { class UnBuffered : public paddle::framework::Channel<T> {
friend Channel<T>* paddle::framework::MakeChannel<T>(size_t); friend Channel<T>* paddle::framework::MakeChannel<T>(size_t);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册