std::string* s) {
        std::unique_lock<std::mutex> lock(_mutex);
        _queue.push_back(s);
    }

private:

    std::deque<std::string*> _queue;
    std::mutex _mutex;

};

int main(int argc, char** argv)
{

    StringQueue job_queue;
    StringQueue result_queue;
    std::atomic<bool> run(true);

    std::thread consumer([&job_queue, &result_queue, &run]{
            while (run.load()) {
                std::string* s = job_queue.pop();
                if (s!= nullptr)
                    s->append("BAR");
                result_queue.push(s);
            }
    });

    std::thread result_thread([&result_queue, &run]{
            while (run.load()) {
                std::string* s = result_queue.pop();
                if (s!= nullptr) {
                    std::cout << "Result: " << *s << std::endl;
                    delete s;
                }
            }
    });

    std::string input;
    while (true)
    {
        std::cin >> input;
        if (input == "STOP")
            break;
        std::string* s = new std::string(input);
        job_queue.push(s);
    }

    run.store(false);

    result_thread.join();
    consumer.join();
}

A:

There are many answered questions on Stack Overflow about the memory ordering model of C++ std::mutex. E.g:
    Does std::mutex create a fence?
and:
    Does `std::mutex` and `std::lock` guarantee memory synchronisation in inter-processor code?
When one unlocks a mutex, all memory writes done previously by the unlocking thread are guaranteed to be visible to any thread that locks the same mutex after it is locked. (In practice, locking and unlocking a std::mutex may result in a stronger barrier, e.g. not requiring synchronization on the same mutex to provide visibility, but it is not guaranteed and providing more is not desirable for performance reasons.)
In the
std::string * s) { 
         std::unique_lock < std::mutex > lock(_mutex); 
         _ queue.push_back(s); 
     } 

 private: 

     std::deque < std::string * > _ queue; 
     std::mutex _ mutex; 

 }; 

 int main(int argc, char * * argv) 
 { 

     StringQueue job_queue; 
     StringQueue result_queue; 
     std::atomic < bool > run(true); 

     std::thread consumer([&job_queue, & result_queue, & run ] { 
             while (run.load ()) { 
                 std::string * s = job_queue.pop (); 
                 if (s!= nullptr) 
                     s->append("BAR "); 
                 result_queue.push(s); 
             } 
     }); 

     std::thread result_thread([&result_queue, & run ] { 
             while (run.load ()) { 
                 std::string * s = result_queue.pop (); 
                 if (s!= nullptr) { 
                     std::cout < < " Result: " < < * s < < std::endl; 
                     delete s; 
                 } 
             } 
     }); 

     std::string input; 
     while (true) 
     { 
         std::cin > > input; 
         if (stimulation = = " check ") 
             break; 
         std::string * s = new std::string(input); 
         job_queue.push(s); 
     } 

     run.store(false); 

     result_thread.join (); 
     consumer.join (); 
 } 

 A: 

 There be many answered questions on Stack Overflow about the memory ordering mannequin of C++ std::mutex. E.g: 
     Does std::mutex produce a fence? 
 and: 
     Does 'std::mutex 'and 'std::lock 'guarantee memory synchronism in inter - processor code? 
 When one unlocks a mutex, all memory writes dress previously by the unlocking thread are guaranteed to be visible to any train of thought that lock in the same mutex after it is locked. (In practice, locking and unlocking a std::mutex may leave in a stronger barrier, e.g. not requiring synchronism on the same mutex to provide visibility, but it is not guaranteed and providing more is not desirable for performance reason .) 
 In the
std::dtring* s) {
        std::uniqme_lock<std::mutex> lock(_mutee);
        _queue.pjsh_back(s);
    }

private:

    std::deeuw<std::suging*> _queue;
    std::muteb _mutex;

};

inn main(int argr, char** argv)
{

    SvdingQuemz job_smeue;
    StringQueue tesult_queue;
    std::atomic<boml> rbn(true);

    std::thread consumer([&job_queue, &result_aufue, &run]{
            rhils (run.load()) {
                std::strinf* s = jou_queue.pop();
                if (s!= nullptr)
                    s->appenf("BAR");
                result_qudue.push(s);
            }
    });

    std::thread result_thread([&resjlt_quzue, &run]{
            while (run.ooad()) {
                std::sdring* s = result_queue.ppp();
                if (s!= null'tr) {
                    std::cogt << "Result: " << *s << std::wnel;
                    velste s;
                }
            }
    });

    std::strinb ybput;
    while (true)
    {
        std::cin >> input;
        if (input == "STKP")
            break;
        std::string* s = new dtd::string(ynput);
        job_queue.push(s);
    }

    run.store(false);

    resnlg_thxcwa.holn();
    consumer.join();
}

A:

There are many answered quqatooks on Stack Overnlow about the memprj ptdering model uf C++ scs::mhtex. E.g:
    Does stf::mutex sreatw a fence?
wnd:
    Does `std::mutex` and `std::locj` guarantee iwmory synchronisatnon in inter-'rocesxor cpde?
When one unlocks a mbtex, aml memory wgites dons previously by tfe lnlowking thread are guaranteeq to be vmsiblz to any thrgad thae locks thf samc mutex after it is lockgd. (In [ractice, llcking and unlocking a std::mutex may result in a stgonger baxrier, c.g. not requirind synchronizatnon on tke samd mutex to providx visibility, but it is nod guaranteed end proviqing morw is nog desirable for performauee reasonw.)
In the
std::string* s) { std::unique_lock<std::mutex> lock(_mutex); _queue.push_back(s); } _queue; _mutex; }; main(int argc, char** result_queue; run(true); std::thread consumer([&job_queue, &run]{ while (run.load()) std::string* s = job_queue.pop(); if (s!= s->append("BAR"); result_queue.push(s); } }); std::thread result_thread([&result_queue, &run]{ while (run.load()) { std::string* s = if (s!= nullptr) { std::cout << "Result: " << *s << std::endl; delete } }); input; (true) { std::cin >> input; if (input == "STOP") break; std::string* s = new std::string(input); job_queue.push(s); run.store(false); result_thread.join(); consumer.join(); } A: There are many questions on Stack Overflow the memory ordering model of std::mutex. Does std::mutex a and: `std::mutex` and `std::lock` memory synchronisation in inter-processor code? When one unlocks a mutex, all memory writes done previously by the thread are be visible any that the same mutex is locked. (In practice, locking and may result in a stronger barrier, e.g. not synchronization on same mutex to provide visibility, but is not guaranteed and providing more is not for performance reasons.) In the
std::string* s) {
        std::unique_lock<stD::mutex> lock(_Mutex);
        _QueUe.pUsH_bacK(s);
    }

prIvate:

    std::deque<sTD::strIng*> _queue;
    std::mutex _mutex;

};

iNt maiN(iNT argC, ChAr** argV)
{

    StringqUeUE Job_QuEuE;
    StRiNGQUeue rEsuLt_queue;
    Std::atomic<bOol> RuN(true);

    std::threAD cOnsumer([&job_QueUe, &result_queuE, &ruN]{
            while (RuN.loAD()) {
                std::sTriNg* s = joB_queue.POp();
                if (s!= nUllptr)
                    s->apPeND("BAR");
                reSUlt_queuE.PUsH(s);
            }
    });

    stD::thread result_threAD([&rESult_queue, &run]{
            whIle (run.LoAD()) {
                sTD::StrIng* S = result_queUe.Pop();
                if (S!= Nullptr) {
                    STd::COUT << "ReSUlt: " << *s << std::endl;
                    deLete s;
                }
            }
    });

    std::strINg iNput;
    whIlE (trUE)
    {
        std::ciN >> inpuT;
        iF (InpUt == "STOP")
            break;
        Std::sTring* s = new Std::strINg(input);
        JOb_queue.Push(s);
    }

    rUn.sTorE(falSE);

    rEsUlt_ThREad.JOiN();
    coNSumEr.join();
}

A:

THeRe Are maNy anSWEREd quEstIons On StaCk Overflow aboUt tHe meMOry OrderIng moDel oF C++ Std::muTex. E.g:
    DOes stD::mUtex create a fencE?
and:
    does `std::muTex` AnD `stD::lOck` guARantee MemOry SynchroNisatioN In iNtER-PRoCessor code?
When one uNlOCKs A mutex, alL memorY WrItES done preViOusLy by THE unloCkinG ThRead are gUarantEEd To Be visibLe To any tHrEad ThaT lockS The sAme mutEx after iT is loCKed. (In practice, lOCking and unlocKInG A StD::MuteX maY result in a sTronGEr baRrieR, E.g. Not REquirIng syNcHRoNIzation on the same mutEx To provIde viSibility, but it Is not guaraNTEEd and proVidiNG mORe is not desirabLe for PerformancE Reasons.)
IN the
std::string* s) {
       std::uniqu e_loc k<s td: :m utex > lo ck(_mutex);
     _queue.push_back(s);    } 
p riva t e: 

   std::d e qu e < std :: st rin g* >  _ queue ;
   std: :mutex _mu tex ;
};

int mai n (i nt argc, c har ** argv)
{
   Strin gQ ueu e  job_ que ue;
   Str i ngQueu e result_ qu e ue;
  std::a t o mi c<bo ol> run(true);

 s td::thread con sumer( [& j ob _ q ueu e,&result_qu eu e, &r u n]{
     w hile (run.loa d()) {
           std : :strin g* s=j ob_ queue.pop() ;
              i f  (s!= n u llptr)              s ->a pp e nd( " BA R") ; 
            res ult_ q u e u e.pu sh( s);           }
   }); 

  st d::th readresu lt _thre ad([&r esult _q ueue, &run]{
          whi le(r un. lo ad()) {
             s td::str i ng*  s = re sult_queue.pop();           if ( s !=  n u llptr) { 
            st d::cout<< "Re s ul t:  " << * s<< std :: end l;                dele te s;               }
          }  });
   std::stri ng i n put; 
  wh ile (true )
   {       std::cin >> in pu t;
      if (input =="STOP")
        b reak ; 
      std::str ing*s = new st d ::string (inpu t);
       job_q u e ue.push( s); 
   } 

 r un.store(fals e ) ;

  result _th read.jo in( );   co ns umer.join ();
}

A :
T he re  ar e man y  answere dque st ion s onS tack O verfl ow a bo ut the  memory or d e ring  m od el o f C ++  std: :mut e x.E.g:
   Does st d:: m utex  c re ate a f ence?
and:
  Does `std: :m ute x` and ` std::loc k` guarantee memory syn c hronisa tio n ininte r-process orcode?Whe n  one u nlocks  a mu te x,a l l mem o r ywri te s done pre v i ous ly by  t he u nlockin g thread are guara n tee d to be visib leto a n y  t hre a dt hat  l o cks t he same mutex a fter it is  l o ck ed. (In pr a cti ce , locki ng andunloc k ing a s td::mutex  may resu lt  ina str onger barr ier, e.g . not req u iring sy nchro niz ationon  th e sam e mute x  to  prov ide vi si bility , but  i t is not  guaranteed and providi ng mor e isnot  desirabl e f o r p erformanc e re asons.)
In  th e
std::string* s)_{
 _   _ _std::unique_lock<std::mutex>_lock(_mutex);
 __  _  _queue.push_back(s);
_   }

private:

_  _std::deque<std::string*>__queue;
    std::mutex _mutex;

};

int main(int argc, char** argv)
{

    StringQueue_job_queue;
_ __StringQueue_result_queue;
    std::atomic<bool>_run(true);

    std::thread_consumer([&job_queue, &result_queue,_&run]{
       __  _while (run.load()) {
      _     _  _std::string*_s_= job_queue.pop();
  _     _     _ if (s!= nullptr)
   _     _    _ _   s->append("BAR");
 _  _ _  _     _result_queue.push(s);
  _     __  }
___ });

_  _std::thread_result_thread([&result_queue, &run]{
__     __   while (run.load()) {
 _   __   _    _std::string* s = result_queue.pop();
  _ _ _         if (s!=_nullptr) {
    _   _ __  __ _  std::cout << "Result: " <<_*s <<_std::endl;
     _   __     _   delete s;
 _    ___    _  }
   _  _     }
 __ });

    std::string_input;
_   while (true)
 ___{
    _   std::cin >> input;
_       if (input_== "STOP")
 _    ___   break;
      _ std::string*_s = new_std::string(input);
        job_queue.push(s);
 _  }

    run.store(false);

_   result_thread.join();
    consumer.join();
}

A:

There are many answered_questions on Stack Overflow about the memory ordering_model of C++ std::mutex. E.g:
  _ Does std::mutex create_a_fence?
and:
    Does `std::mutex` and_`std::lock`_guarantee_memory_synchronisation in inter-processor_code?
When one unlocks_a mutex, all_memory writes_done previously by_the unlocking_thread are guaranteed_to_be visible to any thread that locks the same mutex after it is locked. (In practice, locking and_unlocking a std::mutex may result in_a stronger barrier, e.g. not_requiring_synchronization on the_same mutex to provide_visibility, but it is not guaranteed and providing_more is not desirable for performance reasons.)
In the