Не могу понять, почему у меня не отрабатывает std::thread без вызова cout? Как такое вообще возможно?
/*
* Dispatcher
*/
void threadDispatcherF(FileReaderObject *dev) {
while(true) {
//print messages from bufer to console
string outpMsg = dev->getOutpMsg();
while(!(outpMsg.compare("") == 0)) {
//print message
std::cout << outpMsg;
outpMsg = dev->getOutpMsg();
}
usleep(dev->TIMEOUT_THREAD_US);
}
}
/*
* Initialisation of our reader
*/
void FileReaderObject::init() {
printMessage("File read device. Denis, 2018");
printMessage("Press q for exit");
std::thread threadDispatcher(threadDispatcherF, this);
threadDispatcher.join();
}
class FileReaderObject {
private:
const int TIMEOUT_THREAD_US = 10000;
const int TIMEOUT_WAIT_KEY_MS = 100;
mutex m_mutPrintMsg;
deque<string> m_consoleMsgs;
bool m_needStop;
int setReadParameters();
void printMessage(string msg);
//drive device
string getOutpMsg();
static string getChar();
void setNeedStop();
friend void threadRecvF (FileReaderObject *dev);
friend void threadSendF (FileReaderObject *dev);
friend void threadReadF (FileReaderObject *dev);
friend void threadDispatcherF(FileReaderObject *dev);
public:
FileReaderObject();
~FileReaderObject();
void init();
};