For a channel read in as below:
dataIn :> data ;
Can it be a non-block mode, which mean if there is no input to the channel, it can escape and run next line?
Or is there any function to detect the event for channel data input?
Basic channel communication problem
-
- New User
- Posts: 3
- Joined: Tue Feb 09, 2010 10:05 am
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
You can use a select with a default case:
If there is no data in the channel the default case will be taken.
Code: Select all
select {
case dataIn :> data:
// handle data
break;
default:
break;
}
-
- New User
- Posts: 3
- Joined: Tue Feb 09, 2010 10:05 am
Thanks for yr reply, I have one more question which should be simple. I write some code as below:
2) I intentionally use master as Tx and slave as RX and seem it work, how should I define the master/slave in a transition?
3)One more conceptual question, from the XC mannual, both transation and streaming is for asyn, and streaming
Thx very much for the help ^.^
To test the transaction feature. But i got an error after the RX read the finish channel data like this:int TX(chanend c)
{
int i,j;
slave
{
for (i=0; i <10; i ++)
{
c <: i;
printf("finsih send out %d\n",i);
}
printf("finish all sending\n");
}
return 0;
}
int RX(chanend c)
{
int i,j;
master
{
while(1)
{
c:> i;
printf("finsih recieve %d\n",i);
for(j=0;j<2000;j++)
{
//delay
}
}
}
return 0;
}
int main() {
chan c;
par {
on stdcore [0] : TX (c) ; // Thread X
on stdcore [1] : RX (c) ; // Thread Y
}
return 0;
}
1) Is it I am using a wrong way to doing that or I need some more function to handle the exception.finsih recieve 5
finsih recieve 6
finsih recieve 7
finsih recieve 8
finsih recieve 9
Unhandled exception: ILLEGAL_RESOURCE, data: 0x00010102
2) I intentionally use master as Tx and slave as RX and seem it work, how should I define the master/slave in a transition?
3)One more conceptual question, from the XC mannual, both transation and streaming is for asyn, and streaming
, what does that mean? When will I use streaming over transition?In contrast to transactions,
multiple streams can be processed concurrently
Thx very much for the help ^.^
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
Transactions provide packetised communication. Under the hood end of message tokens are implicitly sent and received at the end of a transaction.
The communications on both sides of the channel must match up. In the slave transaction on the TX side you send 10 integers. In the master transaction on the RX side you try to continuously input integers. When trying to input the 11th integer it will receive the end of message token from the slave transaction instead. The unexpected end of message token will cause an exception.
If you swap the transactions so that TX uses a master transaction and RX uses a slave transaction then after sending the the last integer the slave transaction will pause expecting an end of message from the master transaction. This end of message will never be received because the master transaction still expects to receive more data.
In both cases the program is invalid. It happens to be that with the current ABI one way causes an exception and one causes deadlock. To fix the problem you should change your program so the number of outputs on one side of the transaction match the number of inputs on the other side.
Streaming channels behave like infinite length transactions. The main disadvantage of streaming channels over transactions is that they reserve a dedicated path on the network between the two channel ends. This puts a limit on the number of streaming channels you can declare between cores. The more streaming channels between cores you declare then the less bandwidth there is for all other inter core channel communication.
The communications on both sides of the channel must match up. In the slave transaction on the TX side you send 10 integers. In the master transaction on the RX side you try to continuously input integers. When trying to input the 11th integer it will receive the end of message token from the slave transaction instead. The unexpected end of message token will cause an exception.
If you swap the transactions so that TX uses a master transaction and RX uses a slave transaction then after sending the the last integer the slave transaction will pause expecting an end of message from the master transaction. This end of message will never be received because the master transaction still expects to receive more data.
In both cases the program is invalid. It happens to be that with the current ABI one way causes an exception and one causes deadlock. To fix the problem you should change your program so the number of outputs on one side of the transaction match the number of inputs on the other side.
The XC language disallows nesting of transactions. i.e. On a single thread it is not possible to start a new transaction while in the middle of an existing transaction.3)One more conceptual question, from the XC mannual, both transation and streaming is for asyn, and streaming, what does that mean? When will I use streaming over transition?In contrast to transactions,
multiple streams can be processed concurrently
Streaming channels behave like infinite length transactions. The main disadvantage of streaming channels over transactions is that they reserve a dedicated path on the network between the two channel ends. This puts a limit on the number of streaming channels you can declare between cores. The more streaming channels between cores you declare then the less bandwidth there is for all other inter core channel communication.
-
- New User
- Posts: 3
- Joined: Tue Feb 09, 2010 10:05 am
So there is no different to interchange the master and slave in my code?If you swap the transactions so that TX uses a master transaction and RX uses a slave transaction then after sending the the last integer the slave transaction will pause expecting an end of message from the master transaction. This end of message will never be received because the master transaction still expects to receive more data.
Is it usually a TX will be a master and a RX will be a slave?
Then in what situation there will be different when master and slave is swapped?
Thanks!
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
You can select on the start of a slave transaction, you can't select on the start of a master transaction. If you don't use either end in a select there is no semantic difference if you swap the type of the two transactions.
With the current implementation of selects it is slightly more efficient if you make the transaction which starts with an output the slave, although the difference is minimal either way.
With the current implementation of selects it is slightly more efficient if you make the transaction which starts with an output the slave, although the difference is minimal either way.