Notes on threads - LLdaniel/StellwerkQt GitHub Wiki
For an arbitrary class myClass.h
with functions ::hello
and ::act
one can execute the methods in separate threads shown below:
#include <iostream>
#include <thread>
#include <vector>
#include "myclass.h"
#include <queue>
int main( int argc , char *argv[] ){
myclass c; //initialize object
std::thread t( &myclass::hello , &c); //create thread which executes the hello function
std::thread t2( &myclass::act , &c); //create thread which executes the act function
t.join(); //add it, that it can be executed at the same time
t2.join();
//now the queue test:
std::queue<std::string> q;
q.push("command1");
std::cout<<q.front()<<std::endl;
return 0;
}