Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>class Sample { std::vector&lt;int&gt; v; private: struct Mut; }; struct Sample::Mut { boost::mutex mut_; }; </code></pre> <p>or</p> <pre><code>class Sample { std::vector&lt;int&gt; v; public: boost::shared_ptr&lt;boost::mutex&gt; mutt; Sample() : mutt(new boost::mutex) {} }; </code></pre> <p>now you can refer to the <code>boost::mutex</code> of this sample in other objects providing an access to mutex wrapper, or maybe directly initializing these objects with copy of <code>Mut</code> structure or <code>boost::shared_ptr</code>. <code>boost::shared_ptr</code> is <em>copyable</em> and all its copies <strong>will share</strong> given mutex.</p> <hr> <blockquote> <p>And why can't mutexes be copied?</p> </blockquote> <p>Because mutex is <em>noncopyable</em>. This is it derives from <code>boost::noncopyable</code>:</p> <pre><code>#include &lt;boost/thread/mutex.hpp&gt; class mutex: boost::noncopyable { </code></pre> <blockquote> <p>Class noncopyable is a base class. Derive your own class from noncopyable when you want to prohibit copy construction and copy assignment.</p> </blockquote> <p>You don't need their copy in fact because it would be useless, but rather you want to share same instance in many objects and refer to a single mutex which guards access to single resource. </p> <p>from <code>&lt;boost/noncopyable.hpp&gt;</code> :</p> <pre><code>// Private copy constructor and copy assignment ensure classes derived from // class noncopyable cannot be copied. // Contributed by Dave Abrahams namespace noncopyable_ // protection from unintended ADL { class noncopyable { protected: #ifndef BOOST_NO_DEFAULTED_FUNCTIONS BOOST_CONSTEXPR noncopyable() = default; ~noncopyable() = default; #else noncopyable() {} ~noncopyable() {} #endif #ifndef BOOST_NO_DELETED_FUNCTIONS noncopyable( const noncopyable&amp; ) = delete; noncopyable&amp; operator=( const noncopyable&amp; ) = delete; #else private: // emphasize the following members are private noncopyable( const noncopyable&amp; ); noncopyable&amp; operator=( const noncopyable&amp; ); #endif }; } typedef noncopyable_::noncopyable noncopyable; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload