Channel Bidirectional Communication

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Channel Bidirectional Communication

Post by rp181 »

What happens if two threads, which are joined by a channel, both send data (with neither receiving)? Will the data still be accesible? E.G:

Code: Select all

Thread 1:
chan <: byte;
chan :> byte;

Thread 2:
chan <: byte;
chan :> byte.
Would this block forever (unable to test at the moment)?

I am not intentionally doing this, but I have different threads of different speeds, and I think it may be possible for this situation to arise.
If Thread 1 completes early, and tries to send data to Thread 2, the statement will block. However, Thread 2 completes a bit later, and as a result, both ends have sent data on the channel.


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

A (non-streaming) channel in XC synchronises before and after every
data transfer, on both sides (with OUTCT/CHKCT). So your "chan <: byte"
on one side will not transfer any data before the other side runs a
"chan :> byte". Which means you are deadlocking here.

(You can view such transfers as indivisible events that happen on both
threads at the same time).