Sharing variable betweed Threads

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Carpentier
Member++
Posts: 31
Joined: Fri Aug 31, 2012 3:42 pm

Sharing variable betweed Threads

Post by Carpentier »

Hello,
I know that variable sharing is illegal between threads, and threads should always communicate with channels. And i know also that sharing variable between threads in XC will cause compile error except if the variable is read-only.

Anyway, it is still possible in assembler language to access any memory location from different threads. My question is specially adressed to XMOS processor experts or employee.

What append if writing a variable from a thread and reading the same variable from another thread (on the same core) in assembly language :

1) The processor become mad and lead to un unpredictable state
OR
2) The processor still work fine on other tasks but the reading of the variable is unpredictable ,
giving an intermediate value from a write in progress.
OR
3) The reading of the variable correct, ie giving the most recent value that was written at the same location by the other thread


User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

C

:)
User avatar
Bianco
XCore Expert
Posts: 754
Joined: Thu Dec 10, 2009 6:56 pm

Post by Bianco »

He means 3 :)
User avatar
Carpentier
Member++
Posts: 31
Joined: Fri Aug 31, 2012 3:42 pm

Post by Carpentier »

Thank bianco. The previous answer was not very clear, this is good to receive help in the things i am interested about.
ale500
Respected Member
Posts: 259
Joined: Thu Sep 16, 2010 9:15 am

Post by ale500 »

I have used shared memory from XC and assembler. And you can also do it in C. It is a restriction in XC that two or more threads cannot access the same location, unless read-only.
User avatar
Ross
XCore Expert
Posts: 966
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Bianco wrote:He means 3 :)
Thanks! ;)
Carpentier wrote:Thank bianco. The previous answer was not very clear, this is good to receive help in the things i am interested about.
Sorry, for some reason I read the options as A,B,C, not 1,2,3! Must be working too hard ;)