Dedicated in making future come true: large-scale parallelism.
Laws of the past, like Moore's Law, are losing power. Energy is the key restraint of microprocessors performance improvements. Large-scale parallelism, customized accelerators, data orchestration are coming future.
Your program maintains an array of clients with their bank accounts and supports an operation: transfer money from one bank account to another.
You need to ensure all accounts are in a consistent state, which means that negative balance is not allowed, and total amount of all accounts should not change.
This application defines a producer that generates work tasks and consumers that consume the work tasks. Producer and consumer communication via a queue that has a maximum capacity of 100 tasks. Producer produces tasks that include three actions (insert, delete, lookup). The consumer executes the tasks by operating on a set.
I implemented four solutions using locks, where each solution optimizes upon one before.