CST 334 Week 6 Journal
This week in CST334 we learned about semaphores and the problems that arise in concurrency. TO solve a broad range of concurrency problems you need both locks and conditions. There is a synchronization primitive called a semaphore that can be a lock or condition variable. It is an object with an integer value that we can manipulate. We looked at synchronization problems like the producer consumer problem when semaphores coordinate their threads to stop buffering over or underflows. To fix this problem we have to handle it with mutual exclusion and condition signaling. Another problem is the reader and writer problem which shows the need to balance concurrent access and allowing multiple readers BUT not multiple writers, as we saw in PA5.
We also learned about deadlock which occurs due to complex locking protocols. To create a deadlock 4 things HAVE to occur.
Mutual exclusion- threads claim exclusive control of the sources that they require. Like when a thread grabs a lock
Hold and wait - when threads hold resources that were allocated to them (locks that they have already acquired)
No preemption - resources like locks can not be forcibly removed from threads that rae holding them.
Circular wait - there exists a circular chain of threads such that the threads hold one or more resources (locks) that are being requested by the next thread in the chain.
Not only deadlocks, but there are also atomicity violations which are unprotected critical sections and order violations which are incorrect execution sequences. Solutions to fix this include proper variables to lock them.
Comments
Post a Comment