3

I am implementing the C++ mobile apps to call some process which taking some times to make it done, but I need my apps main thread is still running without any blocking.

Question: Is there any library that could just call runOnUIThread to get back the result on main thread?

Understand that there a lot of answer such as message event queue polling to get back the result on main thread, or using future/promise to keep looping the result. But I don't want these kind of solution to achieve the target.

I believe in C++ way has some function to get back main thread looper and call the function with multiple entry point to main thread? I have red this article, I'm not really understand what it means, hope someone could help.

Cross Thread Call in native C++

alk
  • 69,737
  • 10
  • 105
  • 255
Oktaheta
  • 606
  • 5
  • 21
  • *"Understand that there a lot of answer such as message event queue polling to get back the result on main thread, or using future/promise to keep looping the result. But I don't want these kind of solution."* - in other words you know the solutions available but choose not to use them for unspecified reasons. Voting to close. – John Zwinck May 06 '18 at 06:24
  • I read this question and I don't get it. Are you asking how to pass messages between threads? Also the phrase `Is there any library that could just call runOnUIThread to get back the result on main thread?` is unintelligible. – Mikhail May 06 '18 at 06:29
  • @Mikhail Not passing message between threads, But signal other thread function. For example, Thread A has all the data been initialized, but Thread B has nothing just process a small scope of function, how you can get back the result from Thread B? So far I know the only way is polling a object which is shared between threads. But not everyone can understand or how to poll it. I want to build a simple way. – Oktaheta May 06 '18 at 07:51
  • @Oktaheta Threads are notified through condition variables. Start with `std::condition_variable` or `QWaitCondition`. – Mikhail May 06 '18 at 08:04
  • @Mikhail GUI thread cannot block, so i can't use this condition. – Oktaheta May 06 '18 at 08:18
  • @Oktaheta You're supposed to spin up another thread to process the work.. Look up the example for Qt's `QWaitCondition` its similar to the standard producer consumer queue. – Mikhail May 06 '18 at 08:23

1 Answers1

-1

C++ as a language does not have a standard way of doing cross thread messaging. This means you need to implement your own solution that depends on the frameworks you are using.

doron
  • 27,972
  • 12
  • 65
  • 103