When do we use each of this function calls in a threaded application. given two functions fun1() and fun2() defined in the same class dealing with read/write of data into buffers(queue operation). to achieve multi-threading to these. we would have to run the two functions in a separate thread. now lets say the first function read is called at the start of its thread.
is it better to use moveTothread ( second thread)for function write at the start of the first functions thread
Or
define the second function in a new thread class and call that thread at the start of the first thread.
Like Piotr answered you should really have a look at the link he suggested.
As I understand your problem, that should solve your problem.
This is the simplified code from that blog:
Using
moveToThread
we can change the thread affinity of an object. What the OP asks is how we can run two functions of the same class in different threads.Let class
A
and two functionsf1
andf2
Qt
already provided a class for running functions in different threads and it is calledQtConcurrentRun
The function that is triggered can be either an external function or a member function. So in our case if we wanted from the object itself to start
f1
andf2
in different threads we could do the following inrun()
similarly you could execute any public function of any class concurrently, eg
Notice the difference between the two calls:
In order to check when a concurrently executed function has finished you should use a
QFutureWatcher
.