Page 1 of 1

generate an exception if writing in a channel blocks

Posted: Wed May 16, 2012 1:22 pm
by scrusson
Hi,

Here is a major problem i'm facing with xmos :
I'm trying to create a bidirectional communication between two xs1 cores with one streaming channel. If, for any reason, a thread t0 on core0 sends more than 4 words of 32 bits and a thread t1 on core1 doesn't read them, the thread t0 will block. In this case, is there a way not to block the thread t0 (thanks to an exception or a timout) ?

Thanks

Re: generate an exception if writing in a channel blocks

Posted: Thu May 17, 2012 2:44 am
by segher
The proper way to avoid t0 blocking is of course to not send more
data than t1 can swallow up; so let's assume this is for recovering
from some bad situation, data loss is unavoidable.

When a thread is blocked on some I/O instruction, event or interrupt
requests will still be honoured. I don't think you can set things up
in XC for this, so you'll need some little asm or C code. Your idea
of using a timer is probably the easiest way to go.

Re: generate an exception if writing in a channel blocks

Posted: Thu May 17, 2012 5:51 am
by lilltroll
The ideĆ” is not not loose any data with samples.

If you need a longer buffer, there is code-package for that from XMOS.
You may also use a select() on the RX side. This way you can read in the channeldata when it exists, and choose if you want to discard it on the RX side instead, not stalling the TX side.

Re: generate an exception if writing in a channel blocks

Posted: Wed May 23, 2012 9:29 am
by scrusson
Hi guys, thanks for your replies.

I may need to give you a bit more information of what i'm trying to do. I want to use 4 xs1 cores, each of them must communicate with the other ones. My idea is to create a specific exchange thread for each core which will be dedicated to the communications and will share a streaming channel with each other exchange thread. So, communications should be bidirectional and asynchronous. Imagine that an exchange thread writes some data in the channel and the one who should read them doesn't swallow them. The thread blocks and my whole system is down, which is something i can't afford. My question is : isn't there a way to know that a channel is full and then not write in it or, if a thread fills the entire channel, get out properly without blocking. In another way, implement "a sort of select" on the TX side.

Thank you per advance

Re: generate an exception if writing in a channel blocks

Posted: Wed May 23, 2012 10:52 am
by Andy
Take a look at the thread communication examples on Github. There's a bidirectional buffered example that might suit your needs:

https://github.com/xcore/sw_thread_comm ... rc/main.xc

It works by posting a control token on the channel and waiting for a reply before sending the data. The consumer thread only replies when it is ready to send the data.