Skip to content

Instantly share code, notes, and snippets.

@abhijitiitr
Last active August 29, 2015 14:07
Show Gist options
  • Save abhijitiitr/3a5bc97184d6dd32f97b to your computer and use it in GitHub Desktop.
Save abhijitiitr/3a5bc97184d6dd32f97b to your computer and use it in GitHub Desktop.
% c(binary_test).
% Ref=binary_test:open(<<1>>).
% binary_test:increment(Ref,<<3>>).
%%% The initial value of binary term changes always. Why is this happening?
-module(binary_test).
-export([open/1,increment/2,spawn_concurrent_increment/0,spawn_core/0]).
-on_load(init/0).
init() ->
ok = erlang:load_nif("./binary_test", 0).
open(_T) ->
exit(nif_library_not_loaded).
increment(_R,_B) ->
exit(nif_library_not_loaded).
spawn_concurrent_increment() ->
receive
{From, {data, Ref, BinData}} ->
Pid = spawn(?MODULE, spawn_core, []),
Pid ! {self(), {data_core, Ref, BinData, From}},
spawn_concurrent_increment()
end.
spawn_core() ->
receive
{From, {data_core, Ref, BinData, OrigPid}} ->
Result = increment(Ref, BinData),
OrigPid ! {self(), {result, Result}}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment