-
Notifications
You must be signed in to change notification settings - Fork 1.7k
problem when using a FFI 'C' callback function #40529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yes. From which thread are you trying to do a callback? Is this the Dart thread, or are you trying to do a callback from another thread? |
I'm trying the callback from another thread in 'C' outside the Dart thread. |
Yes, doing a callback from another thread is not supported. Dart has one mutator thread per isolate. If a Dart thread is already running in the isolate, and you would call back from C into Dart with another thread, there would be 2 threads executing Dart code in a single isolate. That would break the concurrency assumptions. Instead, you have to call back into Dart on the main Dart thread. One can notify the main Dart thread asynchronously through a SendPort. Please check this sample: https://dart-review.googlesource.com/c/sdk/+/134704. |
Thanks for the help, I'll follow the example and add adaptor functions to register the port and then to receive callbacks on the 'C' side. I'll use the Dart send message 'C' functions to pass parameter messages into the Dart isolate. Thanks again. |
hi @dcharkes, then when I remove the call to Dart_PostCObject, that issue not occur |
It's my mistake, I should use Dart_PostCObject_DL instead of Dart_PostCObject. now it can work |
since dart 3.1, can use NativeCallable |
I'm on dart 2.7.1 Windows 10 - I'm getting a problem when using a FFI 'C' callback function.
I tried to pass a function pointer to a 'C' method that uses a function call back
When to callback is performed, I'm getting an error message from dart c:\b\s\w\ir\cache\builder\sdk\runtime\vm\runtime_entry.cc: 3217: error: Cannot invoke native callback outside an isolate.
I've tried using an isolate in the registration call but the error still happens
I've seen in issue 37301 that someone has done a callback...
I was wondering if the patch was in 2.7.1 or still on a dev branch ?
Can FFI 'C' callbacks to dart be done yet ?
The text was updated successfully, but these errors were encountered: