|
Boost : |
Subject: Re: [boost] [gsoc] Boost.Process done
From: Claude Quézel (cquezel_at_[hidden])
Date: 2011-02-02 08:08:15
The code is not exception safe if you have to call unlock explicitly.
Claude
2011/2/2 Mathias Gaunard <mathias.gaunard_at_[hidden]>
> 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);
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk