
On 01/02/2011 22:37, Claude Quézel wrote:
I noticed that the boost::process::child does not have a default constructor. If I have a coding requirements like the following example, I would be stuck:
// Note the required default constructor boost::process::child child;
// Create a scope for the mutex guard { boost::lock_guard<boost::mutex> guard(process_launch);
// Here I must do something within guard scope // that must be done with the boost::process::launch do_something();
child = boost::process::launch(exec, args, ctx); }
// ...
boost::process::status s = child.wait();
How about template<typename Lockable> struct lock_maybe_guard { explicit lock_maybe_guard(Lockable& m_) : m(m_), locked(false) { lock(); } void lock() { if(!locked) { m.lock(); locked = true; } } unlock() { if(locked) { m.unlock(); locked = false; } } ~lock_guard() { unlock(); } private: Lockable& m; bool locked; }; boost::process::child child; lock_maybe_guard<boost::mutex> guard(process_launch); // Here I must do something within guard scope // that must be done with the boost::process::launch do_something(); guard.unlock(); child = boost::process::launch(exec, args, ctx);