.NET Framework Developer Center >
.NET Development Forums
>
.NET Base Class Library
>
General design question
General design question
- Hi,
I have a general design question:
There is a junction, with four roads connecting to it. Each road has 2 lanes.
What would be the best way to design a program to handle such junction. It should allow 2 cars 2 go through the junction if they don't interfere each other. and 1 car came in before the other, and they both should use the same part of the junction, the 1st car should get priority. Also, 2 cars may arrive the junction at the exact same time.
What would be the best design for this problem? what exactly should you lock, in order to allow best use of the junction?
Thanks!
Answers
- Hi,
According to your description, we can divide the junction to four key areas: A, B, C and D
+ | +
+ | +
+ | car +
+ | | +
+ | | +
+++++++++ | +++++++++
car --> A | B
---- ---- ---- --- --- --- --- --- --- --- ---
C | D <---- car
+++++++++ | +++++++++
+ | | +
+ | | +
+ car | +
+ | +
+ | +
For this kind of shared resource, supposing all cars have same speed (no priority involved), deadlock only occurs when there are four cars in the key areas, and the four cars have different towardings with each other.
so, take area A for example, the condition to enter A will be:
if ((B is busy && C is busy && D is busy) && (cars in B, C, D and the car that going to enter A have different towardings with each other))
{
// then, area A is NOT allowed to enter.
}
Hope it can show some ideas to you, any response is appreciated.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 8:51 AM
All Replies
- Hi,
According to your description, we can divide the junction to four key areas: A, B, C and D
+ | +
+ | +
+ | car +
+ | | +
+ | | +
+++++++++ | +++++++++
car --> A | B
---- ---- ---- --- --- --- --- --- --- --- ---
C | D <---- car
+++++++++ | +++++++++
+ | | +
+ | | +
+ car | +
+ | +
+ | +
For this kind of shared resource, supposing all cars have same speed (no priority involved), deadlock only occurs when there are four cars in the key areas, and the four cars have different towardings with each other.
so, take area A for example, the condition to enter A will be:
if ((B is busy && C is busy && D is busy) && (cars in B, C, D and the car that going to enter A have different towardings with each other))
{
// then, area A is NOT allowed to enter.
}
Hope it can show some ideas to you, any response is appreciated.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help.- Marked As Answer byeryangMSFT, ModeratorMonday, November 09, 2009 8:51 AM


