Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2004-03-05 12:12:22

At 09:40 AM 3/5/2004, Vladimir Prus wrote:
>I have an application which sometimes fails saying that it can't create a

>directory, because it already exists. The directory is created by
> fs::create_directories("run");
>and the application is multi-threaded. It seems there's a race condition:
> if (ph.empty() || exists(ph)) return;
> // First create branch, by calling ourself recursively
> create_directories(ph.branch_path());
> // Now that parent's path exists, create the directory
> create_directory(ph);
>After one thread checks that 'ph' does not exist, another one creates the

>same directory, so call to 'create_directory' fails.
>What can be done? Basically, adding a mutex for MT build and adding a
>warning to docs are the variants. Opinions?

There is already a general race-condition warning in the docs. See

Even if the filesystem library itself were made thread-safe, the problem
could still happen because the state of the external file system may be
altered by some other process or other machine.

Is there a issue with solving your particular problem by either using your
own mutex, or catching and discarding the exception, or moving the
create_directory() call to prolog code that is single-threaded?


Boost list run by bdawes at, gregod at, cpdaniel at, john at