Hi all,
Any idea how to implement process like:
main ( master?) thread preparing data ( other threads waiting for it.
when data is ready main thread create some ready signal(?)
based on it secondary (slave?)threads reading data and send it into ports.
cicga
XK-1A thread sync
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
-
- Experienced Member
- Posts: 82
- Joined: Fri Nov 05, 2010 2:59 pm
Example edited to take account of Al's suggested corrections:
Do something like:
Max
Do something like:
Code: Select all
// prototypes for forward reference
void masterFunk(chanend cout);
void slaveFunk(chanend cin);
out port myport = XS1_PORT_32A;
channel chan;
int main()
{
par {
masterFunk(chan);
slaveFunk(chan);
}
}
void masterFunk(chanend cout)
{
int result;
while(1) {
// do work
cout <: result;
}
}
void slaveFunk(chanend cin)
{
int result;
while(1) {
cin :> result;
myport <: result;
}
}
Last edited by MaxFlashrom on Mon Oct 17, 2011 8:20 pm, edited 1 time in total.
-
- XCore Legend
- Posts: 1274
- Joined: Thu Dec 10, 2009 10:20 pm
Be careful about using 'master' and 'slave' as these are keywords in XC for Transactions. see the Programming XC PDF - http://www.xmos.com/published/programmi ... os-devices section 3.4. For your example maybe renaming the functions slavefunk and masterfunk so as not to confuse ;-)
regards
Al
regards
Al
-
- Experienced Member
- Posts: 82
- Joined: Fri Nov 05, 2010 2:59 pm
That'll teach me to just make stuff up without trying it in the XDE. The XDE syntax highlighter would have alerted me. I've not played with transactions much, so their reserved-word status didn't stick - either that or the mental FIFO just lost that detail after cramming in some new arcane fact. I did say "something like" the code above. One has allow some work for the reader although perhaps the resulting error would have been somewhat cryptic ;-)Folknology wrote:Be careful about using 'master' and 'slave' as these are keywords in XC for Transactions. see the Programming XC PDF - http://www.xmos.com/published/programmi ... os-devices section 3.4. For your example maybe renaming the functions slavefunk and masterfunk so as not to confuse ;-)
regards
Al
Max.
Last edited by MaxFlashrom on Mon Oct 17, 2011 7:24 pm, edited 1 time in total.
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
MaxFlashrom,
this code is fine for single thread, but a problem is that I need several threads working from one "trigger" signal...
thanks
cicga
this code is fine for single thread, but a problem is that I need several threads working from one "trigger" signal...
thanks
cicga
-
- Experienced Member
- Posts: 82
- Joined: Fri Nov 05, 2010 2:59 pm
Are the slave threads to receive different data from the master, or all the same data?
You can just extend the idea.
One can use arrays of channels and a replicator syntax to make this more elegant, but you get the idea, I hope. There is no "trigger signal" required. XMOS works on events. The threads sleep automatically until they receive data.
Max.
You can just extend the idea.
Code: Select all
int main()
{
par {
mThread(chan1, chan2, chan3, chan4);
sThread1(chan1);
sThread2(chan2);
slhread3(chan3);
slhread4(chan4);
}
}
Max.
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
MaxFlashrom,
ideally threads should work with different arrays generated by one master ]
something like this:
master{
a[x]=x;
b[x]=x+2;
}
svale1{
y = a[x];
bla,bla...
}
slave2{
y = b[x];
bla bla...
}
:shock:
cicga
ideally threads should work with different arrays generated by one master ]
something like this:
master{
a[x]=x;
b[x]=x+2;
}
svale1{
y = a[x];
bla,bla...
}
slave2{
y = b[x];
bla bla...
}
:shock:
cicga
Last edited by cicga on Mon Oct 17, 2011 7:53 pm, edited 1 time in total.
-
- Experienced Member
- Posts: 82
- Joined: Fri Nov 05, 2010 2:59 pm
Well, in your master thread send each chan a different piece of data, thencicga wrote:MaxFlashrom,
threads should work with different arrays generated by one master
:shock:
cicga
Code: Select all
for (n=0; n<10; n++) {
chan1 <: data[0][n];
chan2 <: data[1][n];
chan3 <: data[2][n];
chan4 <: data[3][n];
}
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
Max
thanks a lot - its working :D
cicga
thanks a lot - its working :D
cicga