Function cimba_thread_hooks_set

Function Documentation

void cimba_thread_hooks_set(cimba_thread_init_func *initfunc, void *usrarg, cimba_thread_exit_func *exitfunc)

Set the user-defined thread initialization and termination functions, with the argument to be given to the former. The init function will be called at the start of each new Cimba pthread. Used e.g. to determine CUDA stream parameters for the pthread, using the provided usrarg and the thread (i.e. core) identifier.

The init function’s exit value will be stored as a thread local variable and can be accessed from inside the pthread by calling cimba_thread_context().

Before exiting the thread, the given exit function will be called with the context generated by the init function as its argument, e.g. to free any memory allocations done in the init call.

Parameters:
  • initfunc – A function to be called when starting a new pthread

  • usrarg – An argument to be passed to the initfunc

  • exitfunc – A function to be called before exiting a pthread