On Sun, 16 Dec 2018 at 05:00, Pierre Tempel <pierretem...@gmail.com> wrote:
> > “... programs which rely on [the O_CREAT and O_EXCL flags of > > open(2) to work on filesystems accessed via NFS version 2] for > > performing locking tasks will contain a race condition. The solution > > for performing atomic file locking using a lockfile is to create a > > unique file on the same filesystem (e.g., incorporating hostname and > > pid), use link(2) to make a link to the lockfile and use stat(2) on > > the unique file to check if its link count has increased to 2. Do not > > use the return value of the link(2) call.” > > > > The question is if this applies to current NFS versions (3, 4). > However, If I read this correctly, the link count strategy can be used > to encode more info. However, this again depends on OS-specific > extended attributes, which is contrary to the general file-system based > locking I was looking to create. > > As an aside, I don't quite understand why and how a reader/writer lock > requires/uses a counter. I'd appreciate a link to any documentation > about that. > For a reader/writer lock, the usual semantics allow a single writer but arbitrarily many readers. However we're in a situation where we don't have actual locking primitives. ie. each reader will need its own lockfile - they can't share one - and this the problem a counter addresses (by providing unique files). Of course it also creates another problem, as now how do you atomically check whether anyone has a read lock? Or prevent two processes simultaneously creating a read-lockfile and a write-lockfile? Encoding information into the attributes of a common lockfile seems to suffer similar race conditions, but lets say there's a way to do it. Now one process comes and starts a transaction; obtains a read lock. While it's busy a second process comes and also acquires a read lock. The second query finishes really quick and goes to relinquish its read lock. However it does this, it must leave the overall database in a read-locked state, because the first process is still busy! How would you achieve that without a counter or equivalent mechanism? -Rowan _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users