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.
Using
moveToThreadwe 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
Aand two functionsf1andf2Qtalready provided a class for running functions in different threads and it is calledQtConcurrentRunThe 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
f1andf2in 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.