FFI demo to use external_call pass @export(ABI="C") mojo function to a C function in mojo

Is it possible to pass a function pointer from a @export(ABI="C") Mojo function to a C function?

Use cases may include passing the function pointer to pthread_create, or to any C function that accepts a function pointer as an argument.

I’m not aware of a way to do that which doesn’t invoke a whole pile of ABI-based undefined behavior. It does technically work, but things might break.

Anything involving pthread is likely to break quite badly as there are bits of the runtime which are thread local, and you absolutely can’t touch a python interpreter from another thread due to Mojo not actually using the GIL properly at the moment.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.