5 Sep
2003
5 Sep
'03
1:39 p.m.
I implemented a trivial "database", stored in ordinary files, and had to ensure mutual exclusion of database access between simultaneously running CGI scripts. Since each CGI run is short, I simply locked the entire database for the entire run. Claiming a lock on a file is easy in C (well, it takes 18 lines...), but there's nothing in the standard Haskell libraries that can do it. So I borrowed a little C code from the net, and called it via the FFI.
Locking support is available in the unix package distributed with GHC. See: http://www.haskell.org/ghc/docs/latest/html/unix/System.Posix.IO.html#7 Cheers, Simon