Last active
August 29, 2015 14:07
-
-
Save abhijitiitr/3a5bc97184d6dd32f97b 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
% 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