@@ -87,6 +87,76 @@ The point here is that we need a consistent way to compose types, like in C++ we
### Send and Recv
In Go, we first create a channel as explained in the section above and then perform read and write operations on top of the channels.
```go
ch1 := make(chan int)
ch2 := make(chan int, 100)
```
To write (or perform a `Send` operation) the value of a variable `x`, to channel `ch1` above, we perform the following:
```go
ch1 <- x
fmt.Println("Written to the channel")
```
Now to read (or perform a `Recv` operation) the value stored in `ch2` into a variable `y`, we perform the following:
```go
y <- ch2
fmt.Println("Received from channel")
```
In Fluid, we should be able to perform the above operations on the channel objects as well. As of now, we support two different kinds of channels : [Buffered Channel](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/buffered_channel.h) and [UnBuffered Channel](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/unbuffered_channel.h)
Send and Receive can be performed as following on a buffered channel:
The send and receive operations will be similar for unbuffered channel as well, except for the fact that there is no buffer in an unbuffered channel, so the operations are completely synchronized. For example:
```python
import threading
def send_to_channel(channel, data):
channel.send(data)
# Create an unbuffered channel
ch = fluid.make_channel(dtype=INT)
# Writes and Reads are synchronous otherwise the calls will block.
<p>To write (or perform a <codeclass="docutils literal"><spanclass="pre">Send</span></code> operation) the value of a variable <codeclass="docutils literal"><spanclass="pre">x</span></code>, to channel <codeclass="docutils literal"><spanclass="pre">ch1</span></code> above, we perform the following:</p>
<spanclass="nx">fmt</span><spanclass="p">.</span><spanclass="nx">Println</span><spanclass="p">(</span><spanclass="s">"Written to the channel"</span><spanclass="p">)</span>
</pre></div>
</div>
<p>Now to read (or perform a <codeclass="docutils literal"><spanclass="pre">Recv</span></code> operation) the value stored in <codeclass="docutils literal"><spanclass="pre">ch2</span></code> into a variable <codeclass="docutils literal"><spanclass="pre">y</span></code>, we perform the following:</p>
<spanclass="nx">fmt</span><spanclass="p">.</span><spanclass="nx">Println</span><spanclass="p">(</span><spanclass="s">"Received from channel"</span><spanclass="p">)</span>
</pre></div>
</div>
<p>In Fluid, we should be able to perform the above operations on the channel objects as well. As of now, we support two different kinds of channels : <aclass="reference external"href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/buffered_channel.h">Buffered Channel</a> and <aclass="reference external"href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/unbuffered_channel.h">UnBuffered Channel</a></p>
<p>Send and Receive can be performed as following on a buffered channel:</p>
<p>The send and receive operations will be similar for unbuffered channel as well, except for the fact that there is no buffer in an unbuffered channel, so the operations are completely synchronized. For example:</p>
@@ -87,6 +87,76 @@ The point here is that we need a consistent way to compose types, like in C++ we
### Send and Recv
In Go, we first create a channel as explained in the section above and then perform read and write operations on top of the channels.
```go
ch1 := make(chan int)
ch2 := make(chan int, 100)
```
To write (or perform a `Send` operation) the value of a variable `x`, to channel `ch1` above, we perform the following:
```go
ch1 <- x
fmt.Println("Written to the channel")
```
Now to read (or perform a `Recv` operation) the value stored in `ch2` into a variable `y`, we perform the following:
```go
y <- ch2
fmt.Println("Received from channel")
```
In Fluid, we should be able to perform the above operations on the channel objects as well. As of now, we support two different kinds of channels : [Buffered Channel](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/buffered_channel.h) and [UnBuffered Channel](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/unbuffered_channel.h)
Send and Receive can be performed as following on a buffered channel:
The send and receive operations will be similar for unbuffered channel as well, except for the fact that there is no buffer in an unbuffered channel, so the operations are completely synchronized. For example:
```python
import threading
def send_to_channel(channel, data):
channel.send(data)
# Create an unbuffered channel
ch = fluid.make_channel(dtype=INT)
# Writes and Reads are synchronous otherwise the calls will block.
<p>To write (or perform a <codeclass="docutils literal"><spanclass="pre">Send</span></code> operation) the value of a variable <codeclass="docutils literal"><spanclass="pre">x</span></code>, to channel <codeclass="docutils literal"><spanclass="pre">ch1</span></code> above, we perform the following:</p>
<spanclass="nx">fmt</span><spanclass="p">.</span><spanclass="nx">Println</span><spanclass="p">(</span><spanclass="s">"Written to the channel"</span><spanclass="p">)</span>
</pre></div>
</div>
<p>Now to read (or perform a <codeclass="docutils literal"><spanclass="pre">Recv</span></code> operation) the value stored in <codeclass="docutils literal"><spanclass="pre">ch2</span></code> into a variable <codeclass="docutils literal"><spanclass="pre">y</span></code>, we perform the following:</p>
<spanclass="nx">fmt</span><spanclass="p">.</span><spanclass="nx">Println</span><spanclass="p">(</span><spanclass="s">"Received from channel"</span><spanclass="p">)</span>
</pre></div>
</div>
<p>In Fluid, we should be able to perform the above operations on the channel objects as well. As of now, we support two different kinds of channels : <aclass="reference external"href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/buffered_channel.h">Buffered Channel</a> and <aclass="reference external"href="https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/framework/details/unbuffered_channel.h">UnBuffered Channel</a></p>
<p>Send and Receive can be performed as following on a buffered channel:</p>
<p>The send and receive operations will be similar for unbuffered channel as well, except for the fact that there is no buffer in an unbuffered channel, so the operations are completely synchronized. For example:</p>