File locking & device drivers

Leonid Timochouk L.A.Timochouk@REDACTED
Tue May 14 14:25:22 CEST 2002


Hello Erlang users,

I am trying to implement a file locking capability (an interface to the
"flock" system call) in Erlang. Unfortunately, the "file" module does not
provide it straight away.

My first approach was to build a linked-in device driver, and it works
almost fine (it uses "flock" in non-blocking mode in order not to block
the whole Erlang node). There is a problem, however: it communicates with
the Erlang code by sending messages, and the driver responses come into
the same main message queue of the calling process. Now, suppose we have a
process which reads incoming data from its message queue and writes them
into a file, locking the file each time. Then the whole message queue
would need to be traversed each time by the run-time system when we try to
fetch the driver responses, so saving messages in a file has QUADRATIC
rather than linear complexity w.r.t. the length of the incoming queue.
This is a major inefficiency.

Would modifying the built-in "efile" driver be a better solution? If so,
should "flock" be implemented via "file_output" or "file_outputv"? Why is,
for example, "close" implemented as a "file_outputv" operation, although
it has no "vector" data to deal with? Any guidance to "efile" driver
internals will be very much appreciated.

Sincerely,
Dr. Leonid Timochouk
Computing Laboratory
University of Kent at Canterbury




More information about the erlang-questions mailing list