CST 334 Week 6

 

WELCOME TO WEEK 6

Learning Journal

This week I learned about semaphores, which are objects with an integer value that one can manipulate with the functions `sem_wait()` and `sem_post()`. It is also important to know that the initial value of the semaphore determines the way it will behave. To initialize a semaphore, one must use `sem_init()` which has three parameters, with the third one being the initial value. Depending on that value, the semaphore will behave differently. For example, if its value is 1, it behaves like a lock. However, if you want the semaphore to act like a condition variable, the initial value should be 0. This can be used, for instance, when you want semaphores for ordering. An example provided in the text is if a thread wishes to wait for a list to become non-empty so it can delete an element from it. This is often where a thread waits while another signals that it is done with what it was doing. 


We also learned about concurrency problems that can either be deadlock bugs or non-deadlock bugs. Some of the non-deadlock bugs are atomicity violation bugs, where atomicity is not enforced during execution. Therefore, the code will not execute or work as desired. The solution to this problem would be the implementation of locks around the shared variables. Another non-deadlock bug is order-violation bugs. This type of bug doesn't guarantee that a certain thread that needs to be completed before the second will complete first. The solution here would be to use condition variables to signal that it's complete or wait for completion. This way, the order will be appropriate. I also learned that there are four conditions that need to happen in order for a deadlock bug to occur. These are mutual exclusion, hold-and-wait, no preemption, and circular wait. It is important to note that if any of these four conditions are not met, then deadlock cannot happen. 

Comments

Popular posts from this blog

CST 300 Week 1

CST 300 Week 4

CST 300 Week 3