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
-module(palindrome). | |
-export([server/0, client/2, start_load_balancer/1, test_all/0]). | |
rem_punct(String) -> | |
lists:filter(fun (Ch) -> | |
not lists:member(Ch, "\"'\t\n ") | |
end, | |
String). |
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
-module(mailbox). | |
-export([handle_unordered/0, handle_ordered/1, run/0]). | |
%% Handle messages in the order that they arrive | |
handle_unordered() -> | |
receive | |
stop -> | |
ok; | |
{_, Message} -> |
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
-module(frequency). | |
-export([init/0, loop/1]). | |
allocate({[], Allocated}, _Pid) -> | |
{{[], Allocated}, {error, no_frequency}}; | |
allocate({[Freq | Free], Allocated}, Pid) -> | |
case lists:keymember(Pid, 2, Allocated) of | |
true -> {{[Freq | Free], Allocated}, {error, already_allocated}}; |
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
-module(frequency_updated). | |
-export([loop/1, init/1, stop/0, allocate_freq/0, deallocate_freq/1, demo/0, use_freq/0]). | |
-define(TIMEOUT, 5000). | |
%% server implementation | |
allocate({[], Allocated}, _Pid) -> | |
{{[], Allocated}, {error, no_frequency}}; |
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
-module(frequency_hardened). | |
-export([init/0, start/0, stop/0, allocate/0, deallocate/1]). | |
-define(TIMEOUT, 5000). | |
%% server implementation | |
allocate({[], Allocated}, _Pid) -> | |
{{[], Allocated}, {error, no_frequency}}; |
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
-module(frequency). | |
-export([init/1]). | |
-export([start_freq/1, stop_freq/1, allocate_freq/1, deallocate_freq/2]). | |
-define(TIMEOUT, 5000). | |
%% server implementation | |
allocate({[], Allocated}, _Pid) -> |
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
-module(frequency_server). | |
-behaviour(gen_server). | |
-export([init/1, handle_call/3, handle_cast/2]). | |
-export([start/0, stop/0, allocate/0, deallocate/1]). | |
get_frequencies() -> [10,11,12,13,14,15]. | |
%% gen_sever implementation | |
init(_Args) -> |