An interesting concurrency_control problem implemented by java
Description:There is a bridge with cars coming from two directions. The bridge allows maximum three cars to across it from same direction at same time. To balance two sides, after three cars acrossing the bridge, if there are cars waiting for the bridge on another side, these cars should have the higher priority. If there is no car waiting on another side, the following cars will have same priority.
Assume cars on part A are from left to right, and cars on part B are on reverse direction.
Some boundary cases:
- C_a1 across the bridge, and there is no cars on both side.
- C_a1 across the bridge, and there is car waiting on another side but no coming car from same side.
- C_a1 across the bridge, and there is car coming from same side
- C_a3 (the third car from same side)across the bridge, and there is car waiting on both sides
- C_a3 (the third car from same side)across the bridge, and there is no car waiting on another side
- C_a4 (when there are already three cars on bridge, or only one or two cars on bridge)