-
Concurrency is the idea that multiple processes can be running at the same time, in parallel.
-
This comes with some serious challenges. Often there is overhead trying to split work of a program into multiple parts and it’s a challenge to ensure the data remain intact (data integrity).
-
Activity Prep:
-
For this activity you’ll need:
-
A Stopwatch.
-
You can use your smartphone.
-
A lot of Decks of cards.
-
For n students you’ll need n decks of cards, one per student.
-
Shuffle the decks of cards.
-
You can have students do this when you pass out the decks.
-
Activity:
-
Give each student a shuffled deck of cards.
-
Tell students to sort the deck of cards their own as quickly on your signal.
-
Give the class a consistent order to sort the cards in so everyone sorts them the same way.
-
The order of sorting doesn’t matter so long as the class is consistent.
-
One ordering is to sort by number and then by suit.
-
Order of Suits: spades, clubs, diamonds, hearts
-
On Top: ace of spades, clubs, diamonds, hearts
-
2 of spades, clubs, diamonds, hearts
-
….
-
Last Card bottom: king of hearts
-
Time this activity using your stopwatch.
-
Do you best to keep track of as many times as possible.
-
Record the best times on the board so everyone in class can see.
-
If there are multiple sessions of each class, you can leave the fastest times on the board and have the classes compete for the fastest time.
-
GIve students the signal by saying "Go!"
-
After each person sorts a deck, compare the times with the class.
-
Discuss strategies for how different students sorted the deck. What worked best?
-
Next, break students into pairs, remove half the decks, and have students thoroughly shuffle the remaining decks.
-
Tell students they will be sorting again in groups with the goal of besting the previous times.
-
GIve students the signal by saying "Go!"
-
Make sure to record as many times, including the best time, as you can.
-
After the pairs person sorts a deck, ask students if they did anything differently as a group of two.
-
Compare the new times with the class.
-
After the groups of two have finished, repeat the same process but in groups of four.
-
Remove half the remaining decks and reshuffle the cards.
-
If you have enough time, repeat the same process for groups of 8 and groups of 16. After each round, remember to discuss if any strategies changed.
-
Discussion Topics:
-
Usually around 8 students, most people will realize there’s a big problem with concurrency!
-
Too many cooks in the kitchen makes work harder for everyone, and can slow things down.
-
Discuss with students, how writing parallelized programs can be harder than writing a single piece of code which does everything in order.
-
Extra: This can segue into introducing and discussing an interesting law of computer science called Amdahl’s law.
-
Amdahl’s laws a simple way of modeling how much concurrency can speed up a program. http://en.wikipedia.org/wiki/Amdahl's_law