C Specification

To register a user callback function with a program object, call the function

cl_int clSetProgramReleaseCallback(
    cl_program program,
    void (CL_CALLBACK* pfn_notify)(cl_program program, void* user_data),
    void* user_data);


  • program is a valid program object

  • pfn_notify is the callback function that can be registered by the application. This callback function may be called asynchronously by the OpenCL implementation. It is the applications responsibility to ensure that the callback function is thread safe. The parameters to this callback function are:

    • prog is the program object whose destructors are being called. When the user callback is called by the implementation, this program object is not longer valid. prog is only provided for reference purposes.

    • user_data is a pointer to user supplied data. user_data will be passed as the user_data argument when pfn_notify is called. user data can be NULL.


Each call to clSetProgramReleaseCallback registers the specified user callback function on a callback stack associated with program. The registered user callback functions are called in the reverse order in which they were registered. The user callback functions are called after destructors (if any) for program scope global variables (if any) are called and before the program is released. This provides a mechanism for the application (and libraries) to be notified when destructors are complete.

clSetProgramReleaseCallback returns CL_​SUCCESS if the function is executed successfully. Otherwise, it returns one of the following errors:

  • CL_​INVALID_​PROGRAM if program is not a valid program object.

  • CL_​INVALID_​VALUE if pfn_notify is NULL.

  • CL_​OUT_​OF_​RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.

  • CL_​OUT_​OF_​HOST_​MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.

See Also

Document Notes

For more information, see the OpenCL Specification

This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.

Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.