Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Coroutines package for U++
Re: Coroutines package for U++ [message #59292 is a reply to message #59118] Mon, 12 December 2022 13:48 Go to previous messageGo to next message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
I did not study coroutines yet, but I have a question, maybe you can answer it.
Is it possible some easy way to write a function / method to start rendering some big images or PDFs on other threads and awaiting them, to complete, not blocking the main (GUI) thread, that started it?
And canceling that rendering threads automatically if I leave that context by closing the dialog, that started it?
Re: Coroutines package for U++ [message #59293 is a reply to message #59292] Mon, 12 December 2022 17:42 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Hello zsolt

Quote:
Is it possible some easy way to write a function / method to start rendering some big images or PDFs on other threads and awaiting them, to complete, not blocking the main (GUI) thread, that started it?


In my experience the real question would be: Will it worth it?

My answer would be: No. Because what you describe is already achievable by using Upp::CoWork or Upp::AsyncWork. You can offload a rendering operation using these tools without blocking the gui, check their status and wait for them to join in non-blocking way and cancel them when you need to (AsyncWork has a Cancel method). In fact, I have a small utility (app) called SshGet (an MT Sftp/Scp transfer queque), where I do someting very similar to what you describe (instead of rendering stuff, I am transfering them).

However, the direct answer to your questions is that it is partially possible. cpp/coroutines have a concept called awaitables. You can write an awaitable type (class or functor) and pass the coroutine handle among threads in a lock free way via awaitable. But 1) It is complicated, 2) It wont solve the real problem: termination of a thread. Plus, what you achive in the end will seem to be what CoWork et al. can already do.

This is the reason why I opted to implement a light-weight coroutines interface (only routine and generator types and not the awaitable type.) This makes things simple and clean.


Best regards,
Oblivion





[Updated on: Mon, 12 December 2022 17:45]

Report message to a moderator

Re: Coroutines package for U++ [message #59297 is a reply to message #59293] Mon, 12 December 2022 21:38 Go to previous message
zsolt is currently offline  zsolt
Messages: 693
Registered: December 2005
Location: Budapest, Hungary
Contributor
Thanks, Oblivion. I have started to get the idea behind these concepts, checking your code.

I was thinking about if it could be possible to implement something so simple as Javascript's async/await.
But I concluded the same as you.

Maybe it could be done by combining your coroutine with your AsyncWork and a timer infrastructure calling coroutines until their finished state, but too much work compared to using AsyncWork and showing a progress or using SetTimeCallback() to update the window periodically.

[Updated on: Mon, 12 December 2022 21:38]

Report message to a moderator

Previous Topic: Possible enhancement on UppHub
Next Topic: Links in UppHub
Goto Forum:
  


Current Time: Fri Mar 29 08:19:34 CET 2024

Total time taken to generate the page: 0.02446 seconds