The skeleton code you were given makes calls to rand_r(3) to generate random times for threads to sleep.Read the code segment for additional information. Note that the given code to compute the amount of time to sleep is incorrect, you must fix the potential problems. Work with the code to verify that the numbers being generated to pass into usleep do look random – you will have to restructure calls to rand_r so that you can print the values to standard out for inspection. Work in the skeleton given to you in file prodcons.c to flesh out the functions that model producer and consumer threads.Your textbook gives you a nearly complete solution to implement (9th edition SGG, Chapter 5, Project 3, which is reproduced at the bottom of this lab). Your goal is to modify the ADT so that it works safely in a multi-threaded program. Once your ADT works well for a single-threaded program, spend some time identifying which synchronization mechanisms you can hide behind the API of your circular list. If you haven’t fully tested and debugged your circular list, do not move on to the remainder of this lab. By now, you must have completed the implementation of the ADT and of a program that exercises that implementation (which we called adt-test.c in the pre-lab). Once you have that, the producer and consumer can safely call circular_list_insert and circular_list_removein a multi-threaded context because the synchronized ADT takes proper care of things. Now that you have a single-thread implementation for these functions, you can work to build synchronization into them. Int circular_list_remove(struct circular_list *l, item *i) * i pointer to an item onto which the removed item is copied Int circular_list_insert(struct circular_list *l, item i) * i item to copy into a position of the circular list Int circular_list_create(struct circular_list *l, int size) * 0 if successful, -1 if any error condition is found * size number of items to allocate in circular list * Create a circular list with a pre-defined buffer size. The work you did for the pre-lab implements the following application programming interface (API): Primarily, there is an issue of applying the concept of abstraction: the code would be substantially easier to manage if you had an ADT for the circular-list. Looking at the structure of code given above, you will realize that having the producers and the consumer processes deal directly with synchronization is not ideal. The solution to the problem is presented in structures that delineate the code for the two types of process as shows below. Your textbook, Operating Systems Concepts 10th Ed., by Silberschatz, Galvin, and Gagne, discusses the bounded-buffer problem in the context of the classical synchronization problem of producers and consumers (Section 7.1). By virtue of their scheduling, threads might interrupt each other in the middle of one of these operations leaving the data structure in an inconsistent state. If this list is to be shared by multiple threads, you need to be careful with how you implement functionality to remove and to return a buffer to the data structure. circular-queue) with n buffers, each capable of holding a single value of data type double. Additional students files associated with this lab, as well as any existing solutions can be provided upon request by e-mail to: perronebucknelleduĪssume that you have a circular-list (a.k.a. Permission to reuse this material in parts or in its entirety is granted provided that this credits note is not removed. In this lab, you will learn to work with these two mechanisms for thread synchronization as you implement a solution to the bounded-buffer problem. Fortunately, POSIX gives you the more general-purpose semaphore in the sem_t data data type.
0 Comments
Leave a Reply. |