0
votes

In all samples of gen_server implementations I've saw the ?SERVER is assigned to ?MODULE. Look down here:

-define(SERVER, ?MODULE).
...    
gen_server:start_link({local, ?SERVER}, ?MODULE, [], [])

The idea, I have clued is to run many server processes with different names but implemented in one module. But, when I tried to run server with the name different from module name in my experiments, I always got errors. Can, please, somebody explain me this subtlety.

1
What errors do you get?legoscia
It's strange, but now I have no errors. You may see the results below>UDAV21

1 Answers

1
votes

The code you show does not and cannot implement multiple servers with different names, since the server name is defined as the same as the module name. So if you try with this code to get multiple servers implemented in one module your attempts will fail.

The reason for introducing separate SERVER macro with the same value as MODULE is to make things more explicit. In start_link call the two macros may have the same value, but they serve different purposes, so it is clearer to use two instead of one.