n this handout we revise process

CSD2600, Distributed Computing and Networking Lab 44th October 2016In this handout we revise process creation and communication, and demonstrate a problem arising onlyin concurrent systems.Copy/Paste the following code. You need to figure out how to name the source file.-module(bank).-export([account/1,start/0]).account(Balance) ->receive{set, NewBalance} ->account(NewBalance);{get, From} ->From ! {balance, Balance},account(Balance)end.start() ->Account_PID = spawn(bank, account, [0]),register(account_process, Account_PID).A syntax error means you have not typed in the file correctly. Fix these first!Now, answer the following questions:1. Identify the messages function account sends.Read the documentation on the send operator.2. Identify the messages function account receives.Read the documentation on the receive operator.3. What is the effect of calling the spawn function?Read the documentation on the spawn function.4. What is the effect of calling the register function?Read the documentation on the register function.5. What does function account do?6. What does function start do?In the same source file add the following code. Fill in the dots appropriately.set_bal(B) -> ! {set, B}.get_bal() -> ! {get, self()},receive{balance, B} -> end.deposit(Amount) ->OldBalance = (),NewBalance = OldBalance + Amount,(NewBalance).Once you have done this and have no syntax errors, change the export statement so that all threenew functions above are also exported.Copy/paste the following code in a new source file in the same directory.-module(banktest).-export([start/0, client/1]).start() ->bank:start(),register(tester_process, self()),loop(10, 20, 100).loop(_, _, 0) ->true;loop(Amount1, Amount2, N) ->bank:set_bal(0),client(Amount1),client(Amount2),receivedone -> trueend,receivedone -> trueend,io:format(Expected balance = ~B, actual balance = ~B~n~n,[Amount1 + Amount2, bank:get_bal()]),loop(Amount1, Amount2, N-1).client(Amount) ->bank:deposit(Amount),tester_process ! done.Now, answer these questions:1. What does function client do? Recall what you read about the send (!) operator.2. What does function loop do? Recall what you read about the receive function.3. What does function start do? Recall what you read about the register function.Next, run the function banktest:start() in the shell. What do you observe in the output?Run the function banktest:start() in the shell a few more times (you will need to exit the shell andrestart it). Do you observe any difference?Now, in the new file replace the linesclient(Amount1),client(Amount2),withspawn(banktest, client, [Amount1]),spawn(banktest, client, [Amount2]),What is the meaning of this change? Recall what you read about the spawn function.Finally, do the following:1. Run the function banktest:start() again in the shell. What do you observe in the output?If you do not see anything surprising you may need to run the function a few more times.2. Identify more precisely the problem we observe.3. Can you think of a potential solution?

Pssst…We can write an original essay just for you.

Any essay type. Any subject. We will even overcome a 6 hour deadline.

<< SAVE15 >>

Place your first order with code to get 15% discount right away!

Impressive sample results