Running NIF code in driver handlers
Max Lapshin <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAMxVRxCnNLMzDZrnOricFz3_whCauRFwMSY0K1DMW8g=iq4a+A@mail.gmail.com> |
I've got ab interesting bug. I have a driver (it is more convenient than NIF to handle sockets because the driver has state). I tried to call enif_make_maps from port_call callback and got into following backtrace: erts_maps_put is calling erts_hashmap_insert then it goes into macro ERTS_VERIFY_UNUSED_TEMP_ALLOC(p); then goes to erts_proc_sched_data and fails on ASSERT(ERTS_SCHEDULER_IS_DIRTY(esdp)); Problem is following: I call env = enif_alloc_env(); but I'm running on a scheduler thread, because it is driver port_call callback. I do not have any working process, so c_p->scheduler_data is zero, thus this code assumes that I'm on a dirty scheduler thread. So it seems that it is illegal to call enif_alloc_env in a driver callback and maybe even illegal to do it in a NIF callback because we already have env? Should I create a better test example? Is it a designed behaviour or something that can be fixed?