Can event callbacks be preempted by other event callbacks?

Hi,

I could not find anything in the OpenCL 1.1 standard that talks about preemption of event callback functions by other event callback functions. Could someone enlighten me on this? What happens if multiple OpenCL events register the same callback function to trigger on event completion, and all of the events complete? Are there any guarantees that only a single instance of the callback will be in progress at any given time? If not, is there a way to get a shared callback to run like a critical section? Would spinlocks suffice or are there again no guarantees about progression of state through blocking lock requests?

Many thanks.

Albert.

What happens if multiple OpenCL events register the same callback function to trigger on event completion, and all of the events complete? Are there any guarantees that only a single instance of the callback will be in progress at any given time? If not, is there a way to get a shared callback to run like a critical section?

What will happen is implementation-dependent. In some implementations, multiple different threads may execute the callback simultaneously. There is no guarantee that the callbacks will be executed serially. It’s the application’s responsibility to ensure that the callback is thread-safe.

If you require the callbacks to be serialized, I recommend using a critical section inside the callback function.

I’ve been looking for an answer for this specific problem & now at last I have the possible answer. You’re an angel! Thanks!

For future cases, I recommend reading the OpenCL 1.1 specification available from http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf or at least the man pages available from http://www.khronos.org/registry/cl/sdk/ … man/xhtml/

If you look at the description of function clSetEventCallback() either in the spec or the man pages it says that “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.”