Skip to content

Instantly share code, notes, and snippets.

@SNtGog
Created January 17, 2013 17:44
Show Gist options
  • Save SNtGog/4557886 to your computer and use it in GitHub Desktop.
Save SNtGog/4557886 to your computer and use it in GitHub Desktop.
idea
%% Copyright
-module(test).
-author("Gog").
-compile([export_all]).
%% API
-export([start/0,start/1,for/3]).
start() -> start(30).
start(Threads) -> spawn(fun()->get_count_of_processes()end),
Reciver = spawn(fun() -> ping() end),
for(0,Threads,fun() -> spawn(fun() -> pong(Reciver) end) end).
ping() -> receive
{Sender, Msg} -> Sender ! Msg;
_ -> ok
end,
ping().
pong(Pid) -> Pid ! {self(),"TEST~n"},
receive
Msg -> io:format(Msg)
end,
pong(Pid).
for(Max,Max,F) -> F();
for(I,Max,F) -> [F()|for(I+1,Max,F)].
get_count_of_processes() -> Max = erlang:system_info(process_count),
io:format("Current number of processes:~p~n",[Max]),
receive after 1000 -> ok end,
get_count_of_processes().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment