[erlang-questions] enif_send, how to call off a smp thread?

Vans S vans_163@REDACTED
Tue Mar 21 05:10:43 CET 2017


I am having a weird issue with enif_send.

What is happening is I am interoping with a 3rd party C library which has
its own event loop and procs callbacks from its own thread.

When the callback procs (in the C NIF) I want to call enif_send to get
the message back to an erlang pid.

When I call enif_send the first term I pass it works, then every subsequent message
gets dropped unless its exactly the same as the first time passed.

For example


static ErlNifPid my_temp_pid;
static void on_callback(void* user_data)
{
ErlNifEnv* msg_env = enif_alloc_env();
enif_send(NULL, &my_temp_pid, msg_env, mk_atom(msg_env, "okk"));
enif_send(NULL, &my_temp_pid, msg_env, mk_atom(msg_env, "aaokk"));
enif_free_env(msg_env);}

*on_callback proced
6> receive X-> X after 1 -> none end.
okk

7> receive X-> X after 1 -> none end.none
*on_callback proced
8> receive X-> X after 1 -> none end.
okk
9> receive X-> X after 1 -> none end.
none
*on_callback proced
*on_callback proced
10> receive X-> X after 1 -> none end.
okk
11> receive X-> X after 1 -> none end.
okk
12> receive X-> X after 1 -> none end.
none
What is the correct way to do this? Thanks.



More information about the erlang-questions mailing list