lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

The algorithm uses a symlink-based lockfile on POSIX (I have to make up a more descriptive name than lock_dir, as the lock can be used to as an exclusive lock to any resource). I think mkstemp and symlink are supposed to be atomic, so where is the race condition? See for a high-level description of a similar algorithm, and for a NetBSD implementation of shlock. Lockfiles are a solution that works for both intra and interprocess locks.

If the lock is taken lock_dir returns an error, how to wait until trying again is up to the user. The ideal way would be to have change notification, but this is very system-specific, so unfortunately busy waiting is the easier way...

Obviously I am not married to this solution, so if you have a suggestion on how to implement exclusive locks that works both inside the same process (even in the same thread) and across processes, for both POSIX and Windows, I am all ears. :-)

Fabio Mascarenhas

On Thu, Jul 2, 2009 at 9:43 PM, Edgar Toernig <> wrote:
Leo Razoumov wrote:
> Simple patch below fixed the problem for me.
> @@ -275,7 +275,7 @@ static int lfs_lock_dir(lua_State *L) {

It fixes the compilation problem but that function is still
broken (racy, busy looping, potentional fd and mem leak,
strange algorithm).