Here is a simple problem: A boy and a girl toss a ball back and forth to each other. Assume that the boy is one thread (node) and the girl is another thread, and b is data.
Boy = m
Girl = f
Ball = b
- m has b
- m throws b –> f catches b
- f has b
- f throws b –> m catches b
Assuming we could drop the ball, and holding everything else constant.
- m has b
- m throws b –> f catches b
- m throws b –> f drops b
- f picks up the dropped b
- f has b
- f throws b –> m catches b
- f throws b –> m drops b
- m picks up the dropped b
Suppose you add a third player.
Boy = m
Girl = f
Ball = b
3rd player = x
- m has b
- m throws b –> f catches b
- m throws b –> x catches b
- f has b
- f throws b –> m catches b
- f throws b –> x catches b
- x has b
- x throws b –> m catches b
- x throws b –> f catches b
Assuming we could drop the ball, and holding everything else constant.
- m has b
- m throws b –> f catches b
- m throws b –> f drops b
- f picks up the dropped b
- m throws b –> x catches b
- m throws b –> x drops b
- x picks up the drooped b
- f has b
- f throws b –> m catches b
- f throws b –> m drops b
- m picks up the dropped b
- f throws b –> x catches b
- f throws b –> x drops b
- x picks up the dropped b
- x has b
- x throws b –> m catches b
- x throws b –> m drops b
- m picks up the dropped b
- x throws b –> f catches b
- x throws b –> f drops b
- f picks up the dropped b
Will that change the thread models? What if the throwing pattern is not static; that is, the boy can throw to the girl or to the third player, and so forth?
In this example: Yes, there is an additional thread that gets added, because each player is a tread that can catch or drop a ball. Each player is a thread on its own, transferring data ‘b’ amongst them and throwing the ‘b’ is locking the data before transferring and catching ‘b’ is unlocking the data. After the ball is dropped (maybe calculated randomly), the player with the ball now has to pick it up, which can be equivalent to analyze the data based on a certain condition that is met like account balance is < 500 or else. The model changes with the additional player because each person has a choice to make now on which person should receive the ball next, which is not present in the first model when there were two threads. If there exists a static toss like
- f –> m –> x –> f
Then the model doesn’t change, because there is no choice now.