Try the Dining philosophers problem
It's an excellent metaphor for a classic multi-process synchronization problem.
There are on line examples that show it working, some of which are really quite cool. e.g. one java applet I found with almost no searching :)
Basically the problem goes thusly.
You have five philosophers sitting at a table, each philosopher has a bowl of rice and one chopstick. There is a spare chopstick in the middle of the table, so only one philosopher can eat at any given time (in this universe philosophers only think OR eat).
After eating for a short time the philosopher will put down the communial chopstick, and think for a while, before eating again.
This allows another philosopher to have the chopstick and allows him to eat for a while.
The problem works with any number of philosophers and chopsticks, once chopsticks are less than philosophers.
It applies to threading becase
- Each philosopher is a thread
- The communial chopstick is a resource
needed by all threads.
- Eating is the thread in operation
- Thinking is the thread sleeping, or
at rest.
I've done out the exercise my self, you can use buttons on a form to represent the philosophers/threads, and change the colour of the button to refelect which one is eating/working/has the communial chopstick/resource.
It's a good example because you can test different methods for allocating the chopstick (i.e. a) who ever grabs it first, b) hand around in rotation, c) keep exclusivly until you don't need it anymore). The thread won't finish until all the rice is gone out of the bowl so, if you don't have a fair method of sharing the chopstick, you'll have some bowls finish quickly while some philosophers literally starve.
Hope this helps,
BW