- #1
Eus
- 94
- 0
Hi Ho!
Is there a better way of looking at more than one threads of execution besides enumerating all of the possible paths so that a person can quickly determine whether there will be a problem or not?
When I face a question of determining whether two threads of execution will have a problem of race condition or deadlock or starvation, I try to work out the most possible scenario of having those kind of problems in my head. For example, in case of two threads, I imagine that Thread A is interrupted after executing a certain atomic instruction and Thread B runs up to a certain atomic instruction and so-and-so until I am sure that there will be a/no problem. The difficult part, I think, is in picking the most possible scenario.
Of course I can always enumerate all of the possible scenarios as follows:
Suppose there are two threads: A and B. Each of them has four atomic instructions:
Thread A:
1) A1
2) A2
3) A3
4) A4
Thread B:
1) B1
2) B2
3) B3
4) B4
So, a given scenario always has to execute eight instructions:
For the first instruction (i1), there will be two possibilities: A1 or B1.
For i2, there will be two possibilities for each of the previous possibilities:
if i1 is A1, then i2 is either A2 or B1, whereas
if i1 is B1, then i2 is either A1 or B2, which can be illustrated as:
For i3, there will also be two possibilites for each of the previous possibilities:
And so on ...
But, it is not a good way to enumerate all of them, isn't it? There are going to be [itex]2^8 = 256[/itex] scenarios!
Besides that, how about if each thread nested their instructions inside an infinite loop? Another complication, right?
Therefore, is there any theorem that can guarantee such-and-such or rule-of-thumb that can point out this-and-that?
Thank you very much.
Eus
Is there a better way of looking at more than one threads of execution besides enumerating all of the possible paths so that a person can quickly determine whether there will be a problem or not?
When I face a question of determining whether two threads of execution will have a problem of race condition or deadlock or starvation, I try to work out the most possible scenario of having those kind of problems in my head. For example, in case of two threads, I imagine that Thread A is interrupted after executing a certain atomic instruction and Thread B runs up to a certain atomic instruction and so-and-so until I am sure that there will be a/no problem. The difficult part, I think, is in picking the most possible scenario.
Of course I can always enumerate all of the possible scenarios as follows:
Suppose there are two threads: A and B. Each of them has four atomic instructions:
Thread A:
1) A1
2) A2
3) A3
4) A4
Thread B:
1) B1
2) B2
3) B3
4) B4
So, a given scenario always has to execute eight instructions:
Code:
__ __ __ __ __ __ __ __
i1 i2 i3 i4 i5 i6 i7 i8
For the first instruction (i1), there will be two possibilities: A1 or B1.
For i2, there will be two possibilities for each of the previous possibilities:
if i1 is A1, then i2 is either A2 or B1, whereas
if i1 is B1, then i2 is either A1 or B2, which can be illustrated as:
Code:
A1 A2
B1
B1 A1
B2
For i3, there will also be two possibilites for each of the previous possibilities:
Code:
A1 A2 A3
B1
B1 A2
B2
B1 A1 A2
B2
B2 A1
B3
And so on ...
But, it is not a good way to enumerate all of them, isn't it? There are going to be [itex]2^8 = 256[/itex] scenarios!
Besides that, how about if each thread nested their instructions inside an infinite loop? Another complication, right?
Therefore, is there any theorem that can guarantee such-and-such or rule-of-thumb that can point out this-and-that?
Thank you very much.
Eus