Timeline for If you run a function in a different thread, but you wait for it to finish in your main thread, is that function asynchronous?
Current License: CC BY-SA 4.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 2, 2022 at 6:25 | comment | added | Anon |
@KevinKrumwiede [ Assuming I am understanding your question properly ] There are two ways to wait in a thread: 1) Blocking the thread, waiting for a mutex to unlock. 2) Returning control to the main event loop, which listens for calls to dispatch [ Such as GUI functionality ]. My example does the latter, note: QEventLoop wait; & Object::connect( &fw, &QFutureWatcher<T>::finished, &wait, &QEventLoop::quit ); -- finished is a signal that calls quit() on the local eventloop wait. After that, the main eventloop dispatches control to the code following wait.exec();
|
|
| Aug 1, 2022 at 21:02 | comment | added | Kevin Krumwiede | @Anon Yes, that's how most (all?) UI toolkits work. The code comment says this code doesn't block, but is that true? | |
| Jul 23, 2022 at 22:50 | comment | added | Anon | @KevinKrumwiede The mainthread in Qt is responsible for running the GUI. If you put a resource intensive task on the mainthread, it locks up the GUI. Its not a good thing to do. | |
| Jul 23, 2022 at 4:02 | comment | added | Kevin Krumwiede | If the main thread is waiting for the other thread to finish, why not just have the main thread do what the other thread is doing? | |
| Jul 22, 2022 at 7:04 | comment | added | Ben Cottrell | Does this answer your question? The meaning of asynchronous vs synchronous | |
| Jul 21, 2022 at 22:49 | review | Close votes | |||
| Aug 7, 2022 at 3:07 | |||||
| Jul 21, 2022 at 22:35 | history | edited | Anon | CC BY-SA 4.0 |
edited title
|
| Jul 21, 2022 at 22:10 | history | asked | Anon | CC BY-SA 4.0 |