I’m not an expert on this, but I’ll respond because nobody else has taken it.
A worked out example of distributed computing can be found here:
For your first question, it sounds like you are looking for a SharedArray.
For the second, to prevent a race condition you would use a lock (pointer in the above thread). But I may misunderstand what you are asking for in your last paragraph.