Skip to content

Function lfs.mkdir() is not idempotent and hence not thread safe #156

Open
@alerque

Description

@alerque

Related to #55, but not quite the same ... using lfs.mkdir() is not thread safe. Because it is not idempotent it is quite common to wrap it in a check such as:

if not lfs.attributes(path, "mode") == "directory" then
   lfs.mkdir(path)
end

Unfortunately in a multi-threaded environment is is possible for the directory check to return false but another thread to create the directory in the intervening milliseconds.

A new flag needs to be added so that ERROR_FILE_EXISTS is considered a success because no operation was needed. It's likely the existing syscalls can be leveraged by passing the right flags so the success is properly reported.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions