Skip to content

AUI_THREADPOOL_X#

Executes following {} block asynchronously in the global thread pool. Unlike AUI_THREADPOOL, allows to set lambda's capture but you should always specify lambda's capture.

Header:#include <AUI/Util/kAUI.h>
CMake:aui_link(my_target PUBLIC aui::core)

Definition#

#define AUI_THREADPOOL_X AThreadPool::global()*

Detailed Description#

When AFuture is destroyed, the corresponding AUI_THREADPOOL task is either cancelled or removed from the execution queue. Use AFutureSet or AAsyncHolder to keep multiple AFuture alive.

Example without a return value:

auto task = AUI_THREADPOOL_X [&] {
  AThread::sleep(1000); // a long task
};

Example with a return value:

auto futureStatus = AUI_THREADPOOL_X [&] {
  int status;
  ...
  AThread::sleep(1000); // a long task
  ...
  return status;
};
int status = *futureStatus;