[erlang-questions] Design question

Jim Menard jim.menard@REDACTED
Tue May 1 20:04:46 CEST 2007


I'm a newcomer to Erlang, working my way through Programming Erlang.
To help me learn, I'm porting a small Web application to
Erlang/Erlyweb. Since I am new to Erlang, I have a design question.

In this app, calendar objects are created on the fly, one for each set
of users. The calendars will only live for a short while (ten minutes
after the last recorded use, which gets refreshed if somebody uses it
in that time). The first request for calendar X will create a calendar
with that id.

My first thought is "one spawned process per calendar". Does that make
sense? If so, should I use the process dictionary in the main process
to map a calendar's identifier to the Pid for that calendar's process?

I'm thinking that each calendar process will send a message back to
the main process when it is going to kill itself so the main process
can erase that entry from the process dictionary.

Another question: if I do use the process dictionary to store the
calendar id-to-Pid mapping, isn't that a possible multi-threading
danger zone? If two users ask to create the same calendar at the same
time, I have a possible race condition. This tells me that what I'm
thinking of doing is very, very, wrong. Any suggestions?

Jim
-- 
Jim Menard, jimm@REDACTED, jim.menard@REDACTED
http://www.io.com/~jimm/



More information about the erlang-questions mailing list