You review the design of a module of an online banking system. The module will provide real-time statistics related to payments made by the users. The module must support 1,000 concurrent users. A new instance named Thread1 is created for every user who accesses the banking system. The following pseudocode represents the design of the module. (Line numbers are included for reference only.)
01 var amount = 0 // shared variable represents amount of transfer
02 var credit = 0 // shared variable represents total credit
03 var debit = 0 // shared variable represents total debit
04 Thread1:
05 reads userInput from console
06 amount = userInput
07 creates new Thread2 instance and runs it
08 creates new Thread3 instance and runs it
09 Thread2:
10 value = amount
11 if (value > 0) debit = debit – value
12 Thread3:
13 value = amount
14 if (value > 0) credit = credit + value
A new instance named Thread1 is created for every user who accesses the banking system. You need to ensure that no data race occurs when the module runs.
What should you do?
A.
In the existing design, verify the user input after line 05.
B.
In the existing design, create three critical sections for lines 06, 10, and 13.
C.
Change the design and create one critical section that includes all references to amount.
D.
Change the design and create one critical section that includes all references to userInput.