Created
January 17, 2013 17:44
-
-
Save SNtGog/4557886 to your computer and use it in GitHub Desktop.
idea
This file contains hidden or 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
| %% 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