1) Certainly - unless you have entered a GC free zone
2) val_call will probably make GC calls, either directly when passing args, or indirectly inside the callback, so the native thread will need to be attached to the GC system.
For a native thread, this is done with the set_top_of_stack(&data,true), set_top_of_stack(0,true) pair surrounding the val_call.
3) Same applies to any cffi calls - the threads will need to be attached for the duration of making calls.
Also note that things like arrays and maps are not thread-safe, so if your callback touches these, you will need a mutex.
There are some notes here:
I noticed one issue someone was having with a struct placed in the stack.
Structs will be scanned for pointers, but if you have a pointer member you may run into issues:
struct DataStruct
{
value d;
};
struct SomeStruct
{
value v;
DataStruct *data;
};
Here, if you have SomeStruct on the stack, 'v' will be correctly marked, but the data pointer will not be followed, so 'd' will not be marked.
If you define "-D HXCPP_GC_CHECK_POINTER" when you compile, there are some additional checks that may fire when you try to use an object that escaped marking.
This can happen earlier, so it is better than crashing in the mark phase, and can give a hint about which object needs fixing.
Hugh