uthreads - CS3214 Fall 2011 Exercise 7 Due: Friday, Nov 18,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS3214 Fall 2011 Exercise 7 Due: Friday, Nov 18, 2011. 11:59pm (no extensions). What to submit: A tarball with files uthreads semaphore.c , uthreads mutex.c , and linux lock fairness.c . 1. Cooperative User-Level Threading User-level threading packages have become somewhat of a lost art. Their inherent dis- advantages prevent them from being used in many contexts in which application-level concurrency is required. They do not support the use of multiple CPUs or cores, they lack the ability to preempt an uncooperative threads access to the CPU, and they can make it difficult to prevent the OS from blocking an entire process if a blocking system call is made by a thread. Their advantages include their low cost of context switching, the lack of need for any OS support, and full control over scheduling. Occasionally, they are used in high-performance server designs [1, 2] to increase scalability and push the boundaries of how many concur- rent tasks can be managed on a single CPU or core. In this exercise, you will be implementing mutexes and semaphores for a small user-level threading package. The need for such synchronization devices exists even in an envi- ronment that does not support preemption or allows the use of multiple CPUs, because context switches will still occur if threads block to wait for a resource or event. The directory cs3214/public html/fall2011/exercises/uthreads contains an incomplete implementation of a user-level threading package called uthreads . Your task is to study its implementation and complete the methods associated with the types uthreads mutex t and uthreads sem t , as shown below. / ** * Support for mutexes. * / typedef struct uthreads_mutex { uthreads_t holder; // if NULL, mutex is available; // else denotes thread holding mutex struct list waiters; // waiting threads, if any. } * uthreads_mutex_t; / * Initialize this mutex. * / void uthreads_mutex_init(uthreads_mutex_t m); / * Acquire this mutex. * / void uthreads_mutex_lock(uthreads_mutex_t m); / * Release this mutex. * / void uthreads_mutex_unlock(uthreads_mutex_t m); / ** * Support for semaphores. 1 CS3214 Fall 2011 Exercise 7 * / typedef struct uthreads_sem { int count; // value of semaphore. Always non-negative....
View Full Document

This note was uploaded on 12/31/2011 for the course CS 3214 taught by Professor Staff during the Fall '11 term at Virginia Tech.

Page1 / 6

uthreads - CS3214 Fall 2011 Exercise 7 Due: Friday, Nov 18,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online