How to achieve atomic global variables with multiple processes (not threads)?

Hello.

I’m writing a dynamically scheduled parallel algorithm, which spawns new processes when other processes run out of work. I’m keeping a counter of currently running processes so I don’t spawn more than max available processes. I would like to keep this counter atomic (to prevent data races).

My thought process so far:

  • Process 0 spawns 4 new processes (P1, P2, P3, P4)
  • P0 holds a counter which P1-4 update
  • P1-4 send their updates through a remote channel, and P0 updates the counter
  • P1-4 want to access the counter, but they can’t just call remotecall_fetch since it might change in the meantime

How do I achieve atomicity of this global counter using Julia processes?

Keep the counter on a single process and have the other ones access the counter through it.

Ok, so if I keep the counter on process 0, I can use remotecall_fetch on other processes without problems?