Exemple #1
0
        /*
         * When users presses an amount to withdraw
         * Passes in the amount getting withdrawed
         */
        private void withdrawInstructions(int amount)
        {
            // if statement needed for the semaphore or Mutex
            int balance = activeAccount.getBalance();

            if (dataRace.Checked == false && SemaRadio.Checked == true)
            {
                Console.WriteLine("Sema");
                activeAccount.GetSemaphore().WaitOne();
            }
            else if (dataRace.Checked == false && MutexRadio.Checked == true)
            {
                Console.WriteLine("mutex");
                mutex.WaitOne();
            }

            if (activeAccount.decrementBalance(amount))
            {
                atmManager.log("Successfully withdrawn £" + amount + ".");
                MessageBox.Show("Thank you for withdrawing £" + amount + " \nPlease collect your money");
                withdraw          = true;
                DisplayInput.Text = "";
            }
            else
            {
                atmManager.log("Insufficient balance to withdraw.");
                MessageBox.Show("Insufficent balance withdrawal thing please select another option");
            }

            if (dataRace.Checked == false && SemaRadio.Checked == true)
            {
                Console.WriteLine("Sema");
                activeAccount.GetSemaphore().Release();
            }

            else if (dataRace.Checked == false && MutexRadio.Checked == true)
            {
                Console.WriteLine("mutex");
                mutex.ReleaseMutex();
            }
        }