---
name: "clSetEventCallback"
section: "3clc"
platform: "linux"
package: "opencl-1.2-man-doc"
version: "1.0~svn33624-5.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/clSetEventCallback"
---

# clSetEventCallback(3clc)

Registers a user callback function for a specific command execution status.

## NAME

clSetEventCallback - Registers a user callback function for a specific command execution status.

##

**cl\_int clSetEventCallback(cl\_event** *event***, cl\_int** *command\_exec\_callback\_type***, void (CL\_CALLBACK \****pfn\_event\_notify) (cl\_event event, cl\_int event\_command\_exec\_status, void \*user\_data***), void \****user\_data***);**

## PARAMETERS

*event*

A valid event object.

*command\_exec\_callback\_type*

The command execution status for which the callback is registered. The command execution callback value for which a callback can be registered is **CL\_SUBMITTED**, **CL\_RUNNING**, or **CL\_COMPLETE**. There is no guarantee that the callback functions registered for various execution status values for an event will be called in the exact order that the execution status of a command changes. Furthermore, it should be noted that receiving a call back for an event with a status other than **CL\_COMPLETE**, in no way implies that the memory model or execution model as defined by the OpenCL specification has changed. For example, it is not valid to assume that a corresponding memory transfer has completed unless the event is in a state **CL\_COMPLETE**.

The callback function registered for a *command\_exec\_callback\_type* value of **CL\_COMPLETE** will be called when the command has completed successfully or is abnormally terminated.

*pfn\_event\_notify*

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

• *event* is the event object for which the callback function is invoked.

• *event\_command\_exec\_status* represents the execution status of command for which this callback function is invoked. See the table of values for *param\_value* for [**clGetEventInfo**(3clc)](/clGetEventInfo/3clc.md) for the command execution status values. If the callback is called as the result of the command associated with event being abnormally terminated, an appropriate error code for the error that caused the termination will be passed to *event\_command\_exec\_status* instead.

• *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.

## NOTES

The registered callback function will be called when the execution status of command associated with *event* changes to an execution status equal to or past the status specified by *command\_exec\_status*.

Each call to **clSetEventCallback** registers the specified user callback function on a callback stack associated with *event*. The order in which the registered user callback functions are called is undefined.

All callbacks registered for an event object must be called. All enqueued callbacks shall be called before the event object is destroyed. Callbacks must return promptly. The behavior of calling expensive system routines, OpenCL API calls to create contexts or command-queues, or blocking OpenCL operations from the following list below, in a callback is undefined.

• [**clFinish**(3clc)](/clFinish/3clc.md).RE

• [**clWaitForEvents**(3clc)](/clWaitForEvents/3clc.md).RE

•

blocking calls to [**clEnqueueReadBuffer**(3clc)](/clEnqueueReadBuffer/3clc.md), [**clEnqueueReadBufferRect**(3clc)](/clEnqueueReadBufferRect/3clc.md), [**clEnqueueWriteBuffer**(3clc)](/clEnqueueWriteBuffer/3clc.md), and [**clEnqueueWriteBufferRect**(3clc)](/clEnqueueWriteBufferRect/3clc.md).RE

•

blocking calls to [**clEnqueueReadImage**(3clc)](/clEnqueueReadImage/3clc.md) and [**clEnqueueWriteImage**(3clc)](/clEnqueueWriteImage/3clc.md).RE

•

blocking calls to [**clEnqueueMapBuffer**(3clc)](/clEnqueueMapBuffer/3clc.md) and [**clEnqueueMapImage**(3clc)](/clEnqueueMapImage/3clc.md).RE

•

blocking calls to [**clBuildProgram**(3clc)](/clBuildProgram/3clc.md), [**clCompileProgram**(3clc)](/clCompileProgram/3clc.md), or [**clLinkProgram**(3clc)](/clLinkProgram/3clc.md).

If an application needs to wait for completion of a routine from the above list in a callback, please use the non-blocking form of the function, and assign a completion callback to it to do the remainder of your work. Note that when a callback (or other code) enqueues commands to a command-queue, the commands are not required to begin execution until the queue is flushed. In standard usage, blocking enqueue calls serve this role by implicitly flushing the queue. Since blocking calls are not permitted in callbacks, those callbacks that enqueue commands on a command queue should either call [**clFlush**(3clc)](/clFlush/3clc.md) on the queue before returning or arrange for [**clFlush**(3clc)](/clFlush/3clc.md) to be called later on another thread.

## ERRORS

Returns CL\_SUCCESS if the function is executed successfully. Otherwise, it returns one of the following errors:

• CL\_INVALID\_EVENT if *event* is not a valid event object.

• CL\_INVALID\_VALUE if *pfn\_event\_notify* is NULL or if *command\_exec\_callback\_type* is not **CL\_COMPLETE**.

• 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.

## SPECIFICATION

**OpenCL Specification**\[1\]

## AUTHORS

**The Khronos Group**

## COPYRIGHT

Copyright © 2007-2011 The Khronos Group Inc.\
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.

## NOTES

- 1\.

  OpenCL Specification

  page 183, section 5.9 - Event Objects
