Callback When Event Already Set?

Quick question regarding event callbacks: if an event is already set at the time clSetEventCallback is called to register a callback, will the callback be called? The specific scenario I have in mind is this (this is all in one function):

  1. Enqueue something and get an event
  2. Queued item begins executing on its own, and completes
  3. clSetEventCallback is called for said event (in the code this is right after #1)
  4. Do I need to call clGetEventInfo to enure the event wasn’t already set prior to #3, or will the callback be called at some point in the future??

The spec says “All callbacks registered for an event object must be called. All enqueued callbacks shall be called before the event object is destroyed.” Bottom line, even though the event may have progressed to a later state, the callback is guaranteed to be called for the state it is being register for. In other words, if you register a callback for CL_COMPLETE, but the event is already completed, then during the act of registering the callback will be called.

I had this exact same query, so I read the spec and was horribly confused.

Yes, the spec says, “All callbacks registered for an event object must be called.”, but it also says “The registered callback function will be called when the execution status of command associated with event changes to the execution status specified by command_exec_status.”

So which is it? Called only on the transition to the specified status or called regardless of a transition?

For what is such a simple concept, the standard uses wording that has far to much wiggle room. I’m worried that different implementations may behave wildly differently.

I will work on the assumption that all callbacks will be called back in a timely manner (say, millisecond dealys at most) in both cases - a transition to CL_COMPLETED and a registration of a callback to an already completed event.