title: Unable to understand the boost::mutex error C++
body: <p>I am new to multithreading and I have used the thread pool mechanism to synchronize interactions amongst two classes.</p>
  
  <p>While compiling i am unable to understand the error.</p>
  
  <p>The classes are as below:</p>
  
  <p>InstrumentProcessor.h</p>
  
  <pre><code>1 #ifndef INSTRUMENTPROCESSOR_H
    2 #define INSTRUMENTPROCESSOR_H
    3 
    4 #include &lt;boost/thread/thread.hpp&gt;
    5 #include &lt;boost/thread/mutex.hpp&gt;
    6 #include &lt;boost/algorithm/string.hpp&gt;
    7 #include &lt;boost/lexical_cast.hpp&gt;
    8 #include "Semaphore.h"
    9 #include "Instrument.h"
   10 #include &lt;queue&gt;
   11 #include &lt;string&gt;
   12 #include &lt;vector&gt;
   13 
   14 
   15 class InstrumentProcessor
   16 {
   17         public:
   18         InstrumentProcessor(unsigned int const numThreads);
   19         ~InstrumentProcessor();
   20         bool Start();
   21         bool Stop();
   22         void AddLine(const std::string&amp; LineRead); // Producer
   23 
   24         private:
   25         void Process(); // Worker Function
   26         void ProcessLine(std::string&amp; line); // Consumer
   27 
   28         private:
   29         unsigned int const numThreads_;
   30         boost::mutex ProcessorMutex_;
   31         boost::thread_group ProcessorGroup_;
   32         Semaphore taskCount_;
   33         std::queue&lt;std::string&gt; Line_;
   34         bool stop_;
   35         std::vector&lt;std::string&gt; elements_;
   36         std::vector&lt;Instrument&gt; Instruments_;
   37 };
   38 
   39 #endif /* INSTRUMENTPROCESSOR_H */
  </code></pre>
  
  <p>InstrumentProcessor.cpp</p>
  
  <pre><code>1 #include "InstrumentProcessor.h"
    2 
    3 InstrumentProcessor::InstrumentProcessor(unsigned int const numThreads)
    4 : numThreads_(numThreads), stop_(false)
    5 {
    6         Instruments_.reserve(25);
    7 }
    8 
    9 InstrumentProcessor::~InstrumentProcessor()
   10 {
   11 
   12 }
   13 
   14 bool InstrumentProcessor::Start()
   15 {
   16         std::cout &lt;&lt; "\nParallel Processing Started ...." &lt;&lt; std::endl;
   17         for(unsigned int i=0; i&lt;numThreads_; i++)
   18         {
   19                 ProcessorGroup_.create_thread(boost::bind(&amp;InstrumentProcessor    ::Process, this));
   20         }
   21 
   22         return true;
   23 }
   24 
   25 bool InstrumentProcessor::Stop()
   26 {
   27         stop_ = true;
   28         ProcessorGroup_.join_all();
   29         std::cout &lt;&lt; "\n Parallel Processing Stopped ...." &lt;&lt; std::endl;
   30         return stop_;
   31 }
   32 
   33 
   34 void InstrumentProcessor::Process()
   35 {
   36         while(!stop_)
   37         {
   38                 --taskCount_;
   39                 std::string currentLine;
   40                 {
  41                         boost::mutex::scoped_lock lock(ProcessorMutex_);
   42                         currentLine = Line_.front();
   43                         Line_.pop();
   44                 }
   45                 ProcessLine(currentLine);
   46         }
   47 }
   48 
   49 void InstrumentProcessor::AddLine(const std::string&amp; LineRead)
   50 {
   51         boost::mutex::scoped_lock lock(ProcessorMutex_);
   52         Line_.push(LineRead);
   53         ++taskCount_;
   54 }
   55 
   56 void InstrumentProcessor::ProcessLine(std::string&amp; line)
   57 {
   58         boost::algorithm::split(elements_, line, boost::is_any_of("\t "), boos    t::token_compress_on);
   59         for(unsigned int i=1; i&lt;elements_.size(); i++)
   60         {
   61                 if (elements_[i].compare("nan") == 0)
   62                         continue;
   63                 else
   64                 {
   65                         double data = boost::lexical_cast&lt;double&gt;(elements_[i]    );
   66                         Instruments_[i-1].CleanData(data); // This function makes a call to the Insrument Class member function
   67                 }
   68         }
   69 }
  </code></pre>
  
  <p>Instrument.h</p>
  
  <pre><code>1 #ifndef INSTRUMENT_H
    2 #define INSTRUMENT_H
    3 
    4 #include &lt;iostream&gt;
    5 #include &lt;boost/thread/mutex.hpp&gt;
    6 #include &lt;cmath&gt;
    7 
    8 class Instrument
    9 {
   10         public:
   11         Instrument();
   12         ~Instrument();
   13         bool PopulateData(double&amp; data);
   14         bool CleanData(double&amp; data);
   15         bool PrintData();
   16 
   17         private:
   18         bool getMeanAndStandardDeviation();
   19 
   20         private:
   21         double data_;
   22         int N_;
   23         double Mean_;
   24         double M2_;
   25         double stdDev_;
   26         double InitialValue_;
   27         bool Init_;
   28         boost::mutex InstrumentMutex_;
   29 };
   30 
   31 #endif /* INSTRUMENT_H */
  </code></pre>
  
  <p>Instrument.cpp</p>
  
  <pre><code>1 #include "Instrument.h"
    2 
    3 Instrument::Instrument()
    4 : Init_(false), data_(0.0), Mean_(0.0), stdDev_(0.0), InitialValue_(0.0), N_(0    ), M2_(0.0)
    5 {
    6 
    7 }
    8 
    9 Instrument::~Instrument()
   10 {
   11 
   12 }
   13 
   14 bool Instrument::PopulateData(double&amp; data)
   15 {
   16         data_ = data;
   17         if(!Init_)
   18         {
   19                 InitialValue_ = data_;
   20                 Init_ = true;
   21                 std::cout &lt;&lt; "The initial value is: " &lt;&lt; InitialValue_ &lt;&lt; std:    :endl;
   22         }
   23         return true;
   24 }
   25 
   26 /* Cleaning Part 2:
   27 * Each data point will be represented as the % change from the initial value. 
   28 * This will then be added by 101 so as to get uniform positive value with the 
   29 * origin of the data shifted to init_origin + 101
   30 */
   31 
   32 bool Instrument::CleanData(double&amp; data)
   33 {
   34 
   35         std::cout &lt;&lt; "\nData begin inserted: " &lt;&lt; data &lt;&lt; std::endl;
   36         boost::mutex::scoped_lock lock(InstrumentMutex_);
   37         PopulateData(data);
   38         data_ = ((data_-InitialValue_)/InitialValue_)*100;
   39         data_ += 101;
  40         getMeanAndStandardDeviation();
   41         return true;
   42 }
   43 
   44 // Welford recurrence relation for tick based mean and standard deviation calc    ulation
   45 bool Instrument::getMeanAndStandardDeviation()
   46 {
   47         ++N_;
   48         double delta = data_ - Mean_;
   49         Mean_ += delta/N_;
   50         M2_ += delta*(data_ - Mean_);
   51 
   52         if(N_ &gt;= 2)
   53         {
   54                 double variance = M2_/(N_-1);
   55                 stdDev_ = std::sqrt(variance);
   56         }
   57         return true;
   58 }
   59 
   60 bool Instrument::PrintData()
   61 {
   62         std::cout &lt;&lt; "\nMean: " &lt;&lt; Mean_ &lt;&lt; "Std Dev: " &lt;&lt; stdDev_ &lt;&lt; std::end    l;
   63         return true;
   64 }
  </code></pre>
  
  <p>I am compiling the above with the following compilation line:</p>
  
  <pre><code>g++ -std=c++11 -I /usr/lib/x86_64-linux-gnu -lboost_thread -c InstrumentProcessor.cpp
  </code></pre>
  
  <p>which yields in the below error.</p>
  
  <pre><code>In file included from /usr/include/c++/4.8/memory:64:0,
                   from /usr/include/boost/config/no_tr1/memory.hpp:21,
                   from /usr/include/boost/smart_ptr/shared_ptr.hpp:27,
                   from /usr/include/boost/shared_ptr.hpp:17,
                   from /usr/include/boost/date_time/time_clock.hpp:17,
                   from /usr/include/boost/thread/thread_time.hpp:9,
                   from /usr/include/boost/thread/lock_types.hpp:18,
                   from /usr/include/boost/thread/pthread/thread_data.hpp:12,
                   from /usr/include/boost/thread/thread_only.hpp:17,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from InstrumentProcessor.h:4,
                   from InstrumentProcessor.cpp:1:
  /usr/include/c++/4.8/bits/stl_construct.h: In instantiation of ‘void std::_Construct(_T1*, _Args&amp;&amp; ...) [with _T1 = Instrument; _Args = {Instrument}]’:
  /usr/include/c++/4.8/bits/stl_uninitialized.h:75:53:   required from ‘static _ForwardIterator std::__uninitialized_copy&lt;_TrivialValueTypes&gt;::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&lt;Instrument*&gt;; _ForwardIterator = Instrument*; bool _TrivialValueTypes = false]’
  /usr/include/c++/4.8/bits/stl_uninitialized.h:117:41:   required from ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::move_iterator&lt;Instrument*&gt;; _ForwardIterator = Instrument*]’
  /usr/include/c++/4.8/bits/stl_uninitialized.h:258:63:   required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator&lt;_Tp&gt;&amp;) [with _InputIterator = std::move_iterator&lt;Instrument*&gt;; _ForwardIterator = Instrument*; _Tp = Instrument]’
  /usr/include/c++/4.8/bits/stl_vector.h:1142:29:   required from ‘std::vector&lt;_Tp, _Alloc&gt;::pointer std::vector&lt;_Tp, _Alloc&gt;::_M_allocate_and_copy(std::vector&lt;_Tp, _Alloc&gt;::size_type, _ForwardIterator, _ForwardIterator) [with _ForwardIterator = std::move_iterator&lt;Instrument*&gt;; _Tp = Instrument; _Alloc = std::allocator&lt;Instrument&gt;; std::vector&lt;_Tp, _Alloc&gt;::pointer = Instrument*; std::vector&lt;_Tp, _Alloc&gt;::size_type = long unsigned int]’
  /usr/include/c++/4.8/bits/vector.tcc:75:70:   required from ‘void std::vector&lt;_Tp, _Alloc&gt;::reserve(std::vector&lt;_Tp, _Alloc&gt;::size_type) [with _Tp = Instrument; _Alloc = std::allocator&lt;Instrument&gt;; std::vector&lt;_Tp, _Alloc&gt;::size_type = long unsigned int]’
  InstrumentProcessor.cpp:6:25:   required from here
  /usr/include/c++/4.8/bits/stl_construct.h:75:7: error: use of deleted function ‘Instrument::Instrument(const Instrument&amp;)’
       { ::new(static_cast&lt;void*&gt;(__p)) _T1(std::forward&lt;_Args&gt;(__args)...); }
         ^
  In file included from InstrumentProcessor.h:9:0,
                   from InstrumentProcessor.cpp:1:
  Instrument.h:8:7: note: ‘Instrument::Instrument(const Instrument&amp;)’ is implicitly deleted because the default definition would be ill-formed:
   class Instrument
         ^
  Instrument.h:8:7: error: use of deleted function ‘boost::mutex::mutex(const boost::mutex&amp;)’
  In file included from /usr/include/boost/thread/lock_guard.hpp:11:0,
                   from /usr/include/boost/thread/pthread/thread_data.hpp:11,
                   from /usr/include/boost/thread/thread_only.hpp:17,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from InstrumentProcessor.h:4,
                   from InstrumentProcessor.cpp:1:
  /usr/include/boost/thread/pthread/mutex.hpp:96:9: error: declared here
           BOOST_THREAD_NO_COPYABLE(mutex)
           ^
  </code></pre>
  
  <p>Any help on this will be appreciated.</p>