Search code examples
erlangerlang-otpgen-fsm

Unique atom for gen_fsm:start/3 in Erlang


I'm currently in a project making a gameserver. Every player is supposed have an own process with gen_fsm behavior. To start gen_fsm with start/3 we need a unique atom, currently we use make_ref() and have found a way to make this ref into an atom with ref_to_list/1. But according to this post it is not recommended and I agree with him.

How would you solve this problem? When we start a gen_fsm with the local option we need an atom to identify it.


Solution

  • If you use gen_fsm:start/3 the only atom you need is the callback module name. That way you only have to keep track of a PID (process ID) which will automatically be unique.

    If you need to reach the gen_fsm process later, either save the PID in some sort of mapping table or name the process (as you did).