The simplest way to wrap and access a piece of state is Agent. The module allows one to spawn a process that keeps an arbitrary data structure and allows one to send messages to read and update that structure. Thanks to this the access to the structure is automatically serialized, as the process onl...