CST 334 Week 6
This week I learned about semaphores and how they can function as a lock when used in there most basic sense but offer a number of different utilities as well. A semaphore is assigned an integer value when defined and when sem_wait is called it checks to see if the value of the semaphore is greater than 0 if it is then it is decremented by 1 if the value is 0 then the semaphore will wait until the value is greater than 0 based on a trigger from sem_post which increments the value of the semaphore by 1. Semaphores work great for allowing muliple write programs to enter a critical section at once like in the case of the producer-consumer problem. I also learned about common bugs in multi-threaded programs, deadlock bugs are the scariest as they often cause a restart or a shut down of the program however they are the least common bugs. The two most common are atomicity-bugs and order-violation bugs. Both of these bugs can be solved with careful use of semaphores or locks. Bugs are a scary part of programming but knowing how to work around them is key to implementing working computer systems.
Comments
Post a Comment