2

This might be a trivial question for some erlang veterans but it would be nice to know since it wasn't clear in the documentation. Many distributed systems algorithms make use of the comparability of unique pids to make decisions. Erlang is kind enough to offer build-in comparison of pids, However, I was wandering whether comparisons stay consistent among multiple machines referring to both local and external pids. My guess is there are no comparison guarantees but I might be wrong, am I?

Emil Vikström
  • 90,431
  • 16
  • 141
  • 175
senorcarbone
  • 242
  • 2
  • 8

1 Answers1

4

Erlang stores more than just a simple process ID in its PID structures; the data includes a unique identifier for the remote node (whether it be another local or a remote VM).

See Can someone explain the structure of a Pid in Erlang? for details.

Thus, you're guaranteed to not send a message to the wrong PID on the wrong VM (or misinterpret the source of a received message), at least not without making an error somewhere in your code.

Update: It occurs to me that I may well have been answering the wrong question. If you're asking how the comparisons would work (e.g., if Pid1 < Pid2, whether Pid1 is local or remote), all I can state with some confidence is that the ordering will be constant, based on http://learnyousomeerlang.com/starting-out-for-real#bool-and-compare.

Community
  • 1
  • 1
macintux
  • 894
  • 4
  • 6
  • It seems that `self()` will always start with 0 (<0.x.y>) and thus it is always before any other pid from another node. – EmmanuelMess Jun 16 '21 at 13:07