title: How to implement in erlang
body: <p>I was thinking of using a list to store elements(files)</p>
  
  <p>How do i change the code below so that it would lock one process(user) from accessing one file(element in list), while allowing another process(user) to access the file.</p>
  
  <pre><code>-module(bank).
  -export([account/1, start/0, stop/0, deposit/1, get_bal/0, set_bal/1]).
  
  account(Balance) -&gt;
      receive
          {set, NewBalance} -&gt;
              account(NewBalance);
          {get, From} -&gt;
              From ! {balance, Balance},
              account(Balance);
          stop -&gt; ok
      end.
  
  start() -&gt;
      Account_PID = spawn(bank, account, [0]),
      register(account_process, Account_PID).
  
  stop() -&gt;
      account_process ! stop,
      unregister(account_process).
  
  set_bal(B) -&gt;
      account_process ! {set, B}.
  
  get_bal() -&gt;
      account_process ! {get, self()},
      receive
          {balance, B} -&gt; B
      end.
  
  deposit(Amount) -&gt;
      OldBalance = get_bal(),
      NewBalance = OldBalance + Amount,
      set_bal(NewBalance).
  </code></pre>
  
  <p>and</p>
  
  <pre><code>-module(banktest).
  -export([start/0, client/1]).
  
  start() -&gt;
      bank:start(),
      mutex:start(),
      register(tester_process, self()),
      loop(10, 20, 100),
      unregister(tester_process),
      mutex:stop(),
      bank:stop().
  
  loop(_, _, 0) -&gt;
      true;
  loop(Amount1, Amount2, N) -&gt;
      bank:set_bal(0),
      spawn(banktest, client, [Amount1]),
      spawn(banktest, client, [Amount2]),
      receive
          done -&gt; true
      end,
      receive
          done -&gt; true
      end,
      io:format("Expected balance = ~B, actual balance = ~B~n~n",
                [Amount1 + Amount2, bank:get_bal()]),
      loop(Amount1, Amount2, N-1).
  
  client(Amount) -&gt;
      bank:deposit(Amount),
      tester_process ! done.
  </code></pre>