Opened 13 years ago

Last modified 6 years ago

#3531 reopened Bugs

initial_path is not thread-safe

Reported by: Andrey Semashev Owned by: Beman Dawes
Milestone: Boost 1.41.0 Component: filesystem
Version: Boost 1.40.0 Severity: Problem
Keywords: initial_path Cc: raad@…

Description

The initial_path template function uses function-local static variable and thus is not thread-safe.

The documentation states the recommendadion to call initial_path from the beginning of the main function. However, following it is not sufficient because:

  1. If the application consists of several modules (dll or so), on many architectures each module will contain its own copy of the static variable defined in initial_path. Each copy will be initialized as needed, when initial_path is called from within the corresponding module.
  1. The threads may already be running when initial_path is called. This may be true regardless of whether initial_path is called from main or some another place in a dll.

What makes the problem worse is that there are two such functions, actually: initial_path< path >() and initial_path< wpath >(). Each of them will have the described problem.

Change History (4)

comment:1 by Andrey Semashev, 13 years ago

The suggested solution would be to create a single global variable in the Boost.Filesystem dll, and initialize it of the application startup. On platforms that do not syncronize threads during dll loading (are there any?) one could use call_once from Boost.Thread and initialize it similarly (on the application startup).

comment:2 by Beman Dawes, 12 years ago

Resolution: fixed
Status: newclosed

initial_path() has been deprecated in version 3.

--Beman

comment:3 by Andrey Semashev, 12 years ago

Resolution: fixed
Status: closedreopened
  1. In v.3 the function "complete" uses detail::initial_path which is still not thread-safe.
  2. I don't see the reason for removal of this function.

comment:4 by raad@…, 6 years ago

Cc: raad@… added
Note: See TracTickets for help on using tickets.