This lab illustrates the problem of synchronization when many threads are operating on a shared object. The general issue is called "thread safety", and it is a major cause of errors in computer software.
To the problems on the lab sheet and record your answers here.
- Record average run times.
- Write your explanation of the results. Use good English and proper grammar. Also use good Markdown formatting.
These are the average runtime using 3 or more runs of the application. The Counter class is the object being shared by the threads. The threads use the counter to add and subtract values.
Counter class | Limit | Runtime (sec) |
---|---|---|
Unsynchronized counter | ||
Using ReentrantLock | ||
Syncronized method | ||
AtomicLong for total |
answer the questions (1.1 - 1.3)
How might this affect real applications?
answer questions 3.1 - 3.4
answer question 4
answer question 5
answer question 6