Threads and Scheduling

Annulé Publié le Apr 14, 2003 Paiement à la livraison
Annulé Paiement à la livraison

Description This homework has three parts. 1. Implementation of a multithreaded shell Part 1 : Multithreaded Shell Extend the program written in Homework 1, i.e. the shell you wrote to use threads. The multithreaded program would be modelled on a boss-worker model. One thread would get the input from the user, parse it and queue it on a queue shared by a number of threads. The other threads take the input from the queue and execute the command. For this program, you need to understand thread creation, synchronization and mutual exclusion. When the program is initialized, the threads are created and one of the threads takes over the responsibility for reading and parsing the input. This can be the first thread that is created in the program. Following which, a thread pool of workers can be created. Shared Queue The data structure that makes the multithreaded operation possible is the shared queue. The boss thread writes on the shared queue the command that it has parsed. This operation is a typical producer-consumer relationship with the queue acting as the buffer. The consumers here are the worker threads which just read the commands from the queue, and execute the commands. These threads should therefore be informed when a) The queue gets empty, or b) The queue is no longer empty. This can be done using the conditional variables and allowing the threads to wait on the conditional variables. Also, to maintain the shared queue in a consistent state, you need to provide mutual exclusion, by using locks to prevent concurrent access to the queue. The Master(Boss) Thread The master thread just reads the input and it's operation is just to parse the input and queue it onto the shared queue. This requires use of mutual exclusion for allowing it to be the only thread that is writing on the queue at any given point. The Slave(Worker) Threads The slave threads are used to remove the command structure from the queue and then execute the command. The thre

## Deliverables

The worker thread should now execute the command in the same way that the main thread in the regular shell works, that is to fork() and exec(). The fork is needed because the threads share the address space and therefore the exec would cause the whole process to be lost. System Calls The following system calls are needed to implement the multithreaded shell. thr_create() thr_join() mutex_init() mutex_lock() mutex_unlock() cond_init() cond_wait() cond_signal() The above system calls are not the complete set, you might use some additional system calls in your program PART 2 This part of the homework asks you to implement a user level thread library. It is a very simple barebones library. The only functionality that you are expected to provide is the creation, removal, waiting and scheduling of threads. Since this is a non-preemptive thread library, you are expected to schedule threads only when they voluntarily want to be descheduled. The components that you have to provide but are not apparent from the API are : Queues for the threads, for wait, run etc. Scheduler to schedule the appropriate thread, once a thread yields. Functions to create the thread context to start another thread The details of the API The API exported by your thread library should have the following primitives: Creation of a thread uthr_create(void *(*start_func)(void *), void *arg, int flag, int *thread_id) start_func, arg: The newly created thread starts executing start_func, with argument arg. flags: It's enough to support just the THR_DETACHED flag. thread_id: Unique identifier for the newly created thread Cleanup and terminate the thread uthr_exit(void *status) status: The address of a location where the thread should place its exit status. Yield the processor voluntarily uthr_yield() Wait for a thread to exit uthr_join(int target_thread_id, void **status) target_thread_id: thread_id of an undetached thread for which the current one waits. status: Exit value of the target thread Please see the manpages for thr_create, thr_exit, thr_yield and thr_join for more information about the functionalities and semantics of these calls. For the scheduler, use a simple round robin scheme. You may want to check manpages for getcontext, makecontext, swapcontext and setcontext. part 3 In this part of the homework you are asked to measure and compare the cost(time) to create kernel level and user level threads. The kernel level threads are created using the solaris thread library. You should use the thread library you implement to measure the cost of creating user level threads. The general principles of measurement are the same as in Homework 1 and you have to use the same functions to measure the time. The cost of creation of threads is considered to be the time between the call to create the thread and the time when it starts executing. Your job is to measure this time for both kernel and the user level threads. There are no special caveats in this part of the homework except that you should NOT measure the time for creation of every thread. Instead, create a large number of threads and then average out the time.

## Platform

You should use the cereal cluster to develop and test the programs. Some people were having problems running emacs on cereal. The reason is that the DISPLAY variable was not set properly. The following commands would make it run : On the cereal command prompt write as shown with the name of the machine that you are logged on at the appropriate place cereal$ bash cereal$ export set DISPLAY="local_machine_name":0 On the prompt of your local machine write : local_machine$ xhost +

Odd Jobs

Nº du projet : #2925505

À propos du projet

Projet à distance Actif Dec 11, 2008