6

I am using OpenCL's Java binding provided by lwjgl 3.

When I call the clSetEventCallback, I have to pass a callback function to clSetEventCallback. For each clSetEventCallback call, I created a new callback function from lwjgl's CLEventCallback.create, which eventually calls dyncall's dcbNewCallback().

CLEventCallback myCallback = CLEventCallback.create(new CLEventCallbackI {
  ...
});
clSetEventCallback(..., myCallback, ...);

Since the callback function I passed to clSetEventCallback will be evaluated once and only once, I want to destroy it when it is called by OpenCL.

@Override
public void invoke(long event, int status, long user_data) {
  myCallback.close();
}

The myCallback.close() is provided by lwjgl, and it will eventually calls dyncall's dcbFreeCallback().

The above code runs well for me.

I guess if dyncall creates JMP-like instructions for all CPUs, then it is safe.

However, I did not find any dyncall documentation that allows calling dcbFreeCallback() when the registered callback function is running.

So, is it guaranteed safe on all platforms?

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
Yang Bo
  • 3,586
  • 3
  • 22
  • 35

0 Answers0