I am reading opencl-1.1.pdf. In page 143, there is sample like this:
NOTE: Enqueued commands that specify user events in the event_wait_list argument of
clEnqueue*** commands must ensure that the status of these user events being waited on are set
using clSetUserEventStatus before any OpenCL APIs that release OpenCL objects except for
event objects are called; otherwise the behavior is undefined.
For example, the following code sequence will result in undefined behavior of
clReleaseMemObject.
ev1 = clCreateUserEvent(ctx, NULL);
clEnqueueWriteBuffer(cq, buf1, CL_FALSE, …,
1, &ev1, NULL);
clEnqueueWriteBuffer(cq, buf2, CL_FALSE,…);
clReleaseMemObject(buf2);
clSetUserEventStatus(ev1, CL_COMPLETE);
According to the Note message, I wonder if the example should be like this:
ev1 = clCreateUserEvent(ctx, NULL);
clEnqueueWriteBuffer(cq, buf1, CL_FALSE, …,
1, &ev1, NULL);
clEnqueueWriteBuffer(cq, buf2, CL_FALSE,…);
clReleaseMemObject(buf1);
clSetUserEventStatus(ev1, CL_COMPLETE);
Since buf2 does not wait any user event, there is no side effect if it is released before ev1 is set as CL_COMPLETE.
Am I right?