future_thread


A future thread can be used to process information and store the value for later use when it is done processing. This permits the application to be independent of when the thread actually will finish processing and to retrieve the return value anytime after it is available. This feature enables support for asynchronous operations.

To create a new future thread, construct an os_future_thread with the address of a function, an optional pointer to an argument, and an optional address of a callback function. This creates a thread that executes the specified function with the supplied pointer as its argument and the specified callback function with the pointer to the return value as its argument. The functions must be able to take a void* argument and return a void* .

Once constructed, an os_future_thread object contains functions for starting, changing the user functions, and retrieving the value. The new thread executes concurrently with other threads in the process and can be restarted again.

Library

Thread<ToolKit>

Declaration

#include <ospace/thread/futurthd.h>

class os_future_thread

Interface

Constructor
os_future_thread()
Constructs a future thread.
Constructor
os_future_thread( os_future_thread_func_t func , void* args , os_future_callback_func_t cb_func )
Constructs a future thread associated with a pointer to function, func , with an argument, args (default 0 ), and with a pointer to the callback function, cb_func (default 0 ).
Constructor
template< class Runnable >
os_future_thread( Runnable* runnable , os_future_callback_func_t cb_func )
Constructs a future thread using the runnable object runnable and the call back function cb_func (default 0 ). The void* run() method of runnable is invoked when the thread is started. Note that the compiler must be able to support member templates and OS_ENABLE_MEMBER_TEMPLATE_FEATURES must be defined to use this member function.
Destructor
~os_future_thread()
Destroys the future thread.
result
os_future result()
Returns the result of the function encapsulated within a future, blocking if one is not yet available.
set_user_function
void set_user_function( os_future_thread_func_t func , void* args , os_future_callback_func_t cb_func )
Sets the future thread's user supplied function. The arguments are the same as those described in the os_future_thread constructor.
set_user_function
template< class Runnable >
void set_user_function( Runnable* runnable , os_future_callback_func_t cb_func )
Sets the future thread's user supplied function. The arguments are the same as those described in the os_future_thread constructor. Note that the compiler must be able to support member templates and OS_ENABLE_MEMBER_TEMPLATE_FEATURES must be defined to use this member function.
start
void start()
Starts the execution of the user supplied function within the future thread.

Throws: os_thread_toolkit_error


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.