Now returning to my original problem. I tested various loops and it seems that write to a variable is not volatile even if the variable is marked shared. If I write to a variable several times in a loop, all but the last write are optimized out. The only write is put after the loop. Read works fine now with shared. How can I do volatile writes?