This question already has an answer here:
My question is why does boost::scoped_thread<> t{boost::thread(FactoryThread)}; in this program run the function FactoryThread and using
boost::scoped_thread<> t(boost::thread(FactoryThread));
does not run the function FactoryThread.
#include <iostream>
#include <string>
#include <vector>
#include <mutex>
#include <thread>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/thread/scoped_thread.hpp>
void FactoryThread()
{
std::mutex tempEncryptData;
std::unique_lock<std::mutex> DataThread_one(tempEncryptData);
std::cout << "\nThread started & Mutex locked" << std::endl;
}
int main(int argc, char* argv[])
{
try
{
boost::scoped_thread<> t{boost::thread(FactoryThread)};
}
catch(std::exception& e)
{
std::cout << "Exception!!" <<
e.what() << std::endl;
}
return 0;
}
Thank you.
Aucun commentaire:
Enregistrer un commentaire