Backstory
Probably a stupid question, but I just have a sneaking suspicion that "asynchronous" is the wrong terminology to us for naming my template function here:
template <class T>
auto asynchronous( auto &&lambda )
{
QEventLoop wait;
QFutureWatcher<T> fw;
fw.setFuture( QtConcurrent::run(lambda) );
QObject::connect( &fw, &QFutureWatcher<T>::finished, &wait, &QEventLoop::quit );
wait.exec();
QObject::disconnect( &fw, &QFutureWatcher<T>::finished, &wait, &QEventLoop::quit );
return fw.result();
}
in practice it looks like this:
int n(0);
ct_Start(n); // 0 - Running in main thread
n = asynchronous<int>( [&n](){
// Running in background thread.
// Mainthread is waiting for this lambda to finish
// but mainthread is not locked.
// User Interface will still function.
for ( int i = 0; i < 100000; i++ ){
ct_Debug(n++);
};
return n;
});
ct_Finish(n); // 100000
Question
So generally when you place a function on a seperate thread, allowing the main thread to continue, it is usually called asynchronous. However, while I am not blocking my main thread, it is still waiting for the lambda to finish.
- Is naming this function "asynchronous" misleading?
- Is this example considered synchronous, asynchronous, both, or neither?
- Is there better more specific terminology that could be used instead?
Thanks.