Created
July 8, 2012 22:49
-
-
Save davisp/3073295 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LoadQueue = fun(N) -> | |
lists:foreach(fun(_) -> | |
self() ! foo | |
end, lists:seq(1, N)) | |
end. | |
RunTest = fun() -> | |
lists:foreach(fun(_) -> | |
Ref = termsend:ref(), | |
receive Ref -> ok end | |
end, lists:seq(1, 10000)) | |
end. | |
RunTest(). % This is ~instant | |
LoadQueue(10000). | |
RunTest(). % This is ~30-60s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "erl_nif.h" | |
static ERL_NIF_TERM | |
repeat(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) | |
{ | |
ErlNifEnv* msg_env = enif_alloc_env(); | |
ERL_NIF_TERM ref = enif_make_ref(env); | |
ERL_NIF_TERM msg = enif_make_copy(msg_env, ref); | |
ErlNifPid pid; | |
enif_self(env, &pid); | |
enif_send(env, &pid, msg_env, msg); | |
enif_free_env(msg_env); | |
return ref; | |
} | |
static ErlNifFunc nif_funcs[] = { | |
{"ref", 0, repeat} | |
}; | |
ERL_NIF_INIT(termsend, nif_funcs, NULL, NULL, NULL, NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've also tried creating the Ref in Erlang and passing it as an argument to the NIF but it didn't change the behavior.