Friday, 3 April 2015

std::async, std::future and lambda functions to keep GUIs responsive

It has been quite some time since my last post :)

This week I submitted my first paper as a PhD student in TU Delft and I had to shot some video to show my work. I had to show some analytic routine that require some time to be computed but I wanted to keep my GUI responsive, so that the video would results nice.

Imagine that you have a class that is similar to the following one:
You may want to call a method of the class that it is slow to compute. If you do that in the following way the the (Not Responding) problem in your GUI will occur.
The easiest way to solve this problem is to use some cool features of C++11, std::future, std::async and the lambda functions. I use std::async to launch a thread where a lambda function is used to isolate the slow computation. A std::future is used to check if the asynchronous thread has completed the computation and meanwhile the application is refreshed.
there you go :)

3 comments :

  1. Replies
    1. In responsive GUI design, offloading heavy computations from the main thread ensures smooth and interactive user experiences. Likewise, in the world of interiors, functionality and aesthetics should be balanced. Shop interior, Shop interior design, and Villa interior design demand precision and creativity to achieve Customized Living Spaces. With a focus on Contemporary Design Solutions, Dubai-based interior designers blend Elegant Color Palettes with Creative Room Arrangements to produce Elegant Space Planning. Applying innovative concepts, the Contemporary designers transform ideas into reality and set benchmarks for Contemporary design studios worldwide.

      Delete
  2. 3 types of iron oxide - titanium screws & tips - Titanium
    The titanium-teeth tips that you can titanium rod use at work, while also titanium white dominus price maintaining consistent contact and babyliss pro nano titanium curling iron a quality benjamin moore titanium working titanium rod in femur complications life, are often called titanium-teeth

    ReplyDelete