[Boost-bugs] [Boost C++ Libraries] #9614: Optional File Creation for boost::interprocess::file_lock

Subject: [Boost-bugs] [Boost C++ Libraries] #9614: Optional File Creation for boost::interprocess::file_lock
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-01-28 21:54:43


#9614: Optional File Creation for boost::interprocess::file_lock
------------------------------------+--------------------------
 Reporter: Peter LaDow <petela@…> | Owner: igaztanaga
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: interprocess
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: |
------------------------------------+--------------------------
 An optional overload (default second argument?) for the constructor to
 create and open the file to use for the file_lock would be very useful.

 Currently, when creating a file lock, I typically do something like:

 {{{
 std::ofstream tmpf(/path/to/lock/file); tmpf.close();
 boost::interprocess:file_lock f_lock(/path/to/lock/file);
 }}}

 Say I have a class, such as:

 {{{
 class Foo
 {
   public:
     Foo();

   private:
     boost::interprocess::file_lock f_lock;
 };
 }}}

 I have to do the following in the constructor:

 {{{
 Foo::Foo()
 {
   std::ofstream tmpf(/path/to/lock/file); tmpf.close();
   boost::interprocess:file_lock tmp_lock(/path/to/lock/file);

   f_lock.swap(tmp_lock);
 }
 }}}

 This is cumbersome and limits usefulness in initializer lists. Tweaking
 the constructor to something like:

 {{{
 file_lock::file_lock(const char *path, bool create = false);
 }}}

 Would allow a constructor to do the following:

 {{{
 Foo::Foo()
   : f_lock(/path/to/file/lock, true)
 {
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9614>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC