Computer Science 225
Advanced Programming
Spring 2021, Siena College
Lecture 16: Dangers of Concurrency
Date: Friday, April 23, 2021
Agenda
- Announcements
- lots going on!
- Lab 8: Animation (in Canvas and GitHub)
- not due until May 4 or 5 depending on your lab section
- if you have finished the required functionality (as many
have) and decide to go back to add some bonus functionality, be
sure to let me know so I notice it
- the threading and animation aspect of this lab is not fair
game for the exam next week, but the code refactoring to add a
common base class is
- Problem Set 5
- groups are formed, repositories created, now let's get it done
- very good practice for the upcoming exam
- Final Project
- everyone should have been adding to the shared document for
group formation and topic selection by now
- groups need to be formed and repositories created by Monday
- Proposals not due until Friday, but you are encouraged to
get them in so I can check them sooner
- Exam 2 - see the information/study guide shared document
- Finishing up the "windy" in-class excercise from last time
- Dangers of concurrency
- In-class exercise (5 points), create a Google document in your
shared CSIS 225 folder for your response.
- Build a table that lists all of the possible interleavings of
the instructions in the notes where Thread A and Thread B
concurrently execute an increment and a decrement of the same
variable counter.
- Suppose the counter variable starts at 0 before any of
the statements are executed. Add a column to your table that
gives the value of counter after the statements have been
executed.
- Highlight the rows so that ones for which counter will
have the correct final value (that is, the same as it was when we
started) in green, and ones that give an incorrect answer in
red.
Terminology
- interleaving of operations
- interference
- race condition
- process or thread synchronization
Examples