Commit 3abb62f0 authored by cdf009's avatar cdf009

prelab

parent 25736288
1) Describe the difference between mutex and semaphore.
Mutex uses locks to syncronize who and what is acessing a resource. When you use mutex, only one of the tasks can be accessing the resource at once. You will need to lock the other task. The task that is accessing the resource is the only one that can release the lock on the other task (meanign when the task stops accessing the resource, it will allow for the idle task to start accessing). The Semaphore is different because it sends a signal to alert the other task that it is done. For example, if two people are trying to use that bathroom the one accessing the bathroom will have to hold the bathroom pass. When they are done using the bathroom pass, the other task can pick up that pass and do their task. The semaphore can experience different states in the processes while the mutex either has a task locked or unlocked.
2)
pthread_mutex_init: This call will initialize that mutex for the tasks. The initialization is needed to start locking and unlocking tasks. The initialization default will make the mutex initialized and unlocked.
pthread_mutex_lock: This call will lock the task so that the other task can access the resource. By calling this, the task will stay locked until the other task is done and mutex is then availible.
pthread_mutex_unlock: This call will unlock the locked task so that it too can access the resource. This call will unlock the task that is referenced by the mutex. If there is a situation where both tasks are unlocked by using this call, the shcuelder will use policy to decied which task should accquire the mutex.
sem_init(3): This call will initilaize an unamed semaphore. The call will initialize the unamed semphore at the address decralred by sem. The call will also take in a value as an argument that will act as the initialization value.
sem_wait(3): This is the call that will lock the task in a semaphore that is pointed to by sem. This is the time that when the value is zero the call will lock the task until it recieves word that it is time to be unlocked. If the value is greater than zero, the funcion will lock and then return immediately.
sem post(3): This is the call that will unlock the task that was currently locked. If the value is greater than zero, the task will be able to operate and the other task will be blocked. The tasks will then trade off when the active task value becomes 0 and the locked task becomes greater than 0.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment