Error handling

Updated: April 19, 2023

If you write your own main processing loop, you can handle errors as required. But with a thread pool, that code is hidden. To help you detect and respond to errors, the thread pool lets you configure an error handler, error_func(), that is called if your context_alloc(), block_func(), or handler_func() fails.

The function is always called on a context_alloc() failure. For block_func() or handler_func() failures, you can pass the following flags values to thread_pool_create() to specify when you want error_func() called:

If a process sets either POOL_FLAG_CALL_BLOCK_ERRF or POOL_FLAG_CALL_HANDLE_ERRF but doesn't supply error_func(), and such an error occurs, a worker thread will terminate the process via the abort() function.
The error_func() function has the following syntax:
void (*error_func)
         (unsigned flags, int err_value);

When calling error_func(), a worker thread in the thread pool passes a flags field that indicates which functions failed; it also passes the errno value after those functions have returned as err_value. See thread_pool_create() in the QNX Neutrino Utilities Reference for the flags values that the worker thread could pass to error_func().

If you're using a thread pool for a resource manager, it's normal for handler_func() to fail. A block_func() failure, on the other hand, is typically a fatal condition.