I have been trying to do something as illustrated in the code below. Here the goal is having one shared variable whose value is updated by thread1 and then another thread2 reads the value of the variable. In my case the real application would be a circular array queue and the values to be written/read are the tail and the head indexes.
Code: Select all
int var=0;
extern inline int get_var();
extern inline void set_var(int x);
int main()
{
par
{
{
while(get_var()!=1)
;
printstr("var read is 1\n");
}
{
set_var(1);
printstr("var set to 1\n");
}
}
}
Code: Select all
#define create_getsetvar \
inline int get_var() { \
int x=0; \
asm("add %0, %1, 0": "=r"(x),: "r"(var)); \
return x; \
} \
inline void set_var(int x) { \
asm("add %0, %1, 0": "=r"(var),: "r"(x)); \
}
create_getsetvar
Do you know any turnaround for this? It doesn't seem possible to disactivate optimisation just for a code block or function...
Of course I could simply drop the inline specifier and define the two functions in a c module with var being volatile. But my goal is to achieve the maximal performance.