CST 334 - Learning Journal WK VI
What I learned this week in CST 334 is a topic called “Concurrency
Problems”, these are problems that are caused by either in proper locking,
unlocking, incorrect atomicity, or deadlocks. To be more specific Non dead lock
bugs are very common, they are usually caused by atomicity violation and order
violation. On the other hand, there is also dead lock bugs which are less common
and more severe and tricky. An atomicity violation is a sequence of operation
that should be called or not called at all. If interrupted, this causes
unexpected behavior, one can fix atomicity violation by properly utilizing
locks+ unlocks.
I also learned about yielding, this can help but when used
with multi-thread can be resources intensive. Instead, we can use sleeping
locks, they put threads to sleep instead of consistency looping. In Linux, they
are called futex(). We learned that Semaphores are very useful all-purpose synchronization
logics use for locking, ordering, resource control and more. We must use them
with respect to best practice rules to avoid deadlocking and/or bugs.
With all of these modern technologies, comes more complexity.
I learned about the primate solutions such as disable interrupts, simple flags that
use a flag variable for lock/unlock. They relied on hardware and software as
well. Using Atomic instructions such as test and set in 1 step. They can be
used to build spin locks which are threads that spin until the lock is free.
Compare and swap checks if the value equal that’s expected, then it swaps. Ticket
fairness gets a ticket for each thread. It keeps track of whose turn it is by
using a variable in the code. This allows each thread to get a turn, hence
avoiding starvation.
Comments
Post a Comment