boost::flyweights::intermodule_holder

"Foelsche, Peter via Boost-users" <[email protected]> Thu, 9 May 2024 14:41:50 +0000
Newsgroups gmane.comp.lib.boost.user
Message-ID <MN2PR07MB7341522C17AE30B1B93A65769AE62@MN2PR07MB7341.namprd07.prod.outlook.com>
Dear All,

Thanks for the boost library!

Apparently the boost::flyweight::intermodule_holder on LINUX is creating shared memory objects, which by accident (crash?) can persist after the process having created them is already gone.
As a result I ran into the following situation:
I could not successfully run some code, as it attempted to create an already existing shared memory object created by another user.

Would the following be a solution to this problem:

Use a copy of the code of the static_holder inside another namespace as attached and compile one module with __INCLUDE_HOLDER__ defined and all the rest without this define?

Peter

_______________________________________________
Boost-users mailing list
[email protected]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
static_holder.hxx (text/plain, 801 B)
#pragma once

#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/flyweight/static_holder_fwd.hpp>
#include <boost/flyweight/holder_tag.hpp>
#include <boost/mpl/aux_/lambda_support.hpp>

namespace TDA{

namespace flyweights{

template<typename C>
struct static_holder_class:boost::flyweights::holder_marker
{
#ifdef __INCLUDE_HOLDER__
	static C& get()
	{	static C c;
		return c;
	}
#else
#error
	static C& get();
#endif

  typedef static_holder_class type;
  BOOST_MPL_AUX_LAMBDA_SUPPORT(1,static_holder_class,(C))
};

/* static_holder_class specifier */

struct static_holder:boost::flyweights::holder_marker
{
  template<typename C>
  struct apply
  {
    typedef static_holder_class<C> type;
  };
};

} /* namespace flyweights */

} /* namespace boost */