![]() 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. Learn to work with Unix and Pthread synchronization mechanisms.The Pthread library offers the pthread_mutex_t data type, which is much like a binary semaphore and therefore somewhat of limited utility in the solution of synchronization problems.Your task is to complete the following chart. ![]() To simplify, we assume that scheduling is such that processes are never interrupted while executing a given portion of code p1, or p2. ![]() In the scheduling chart below, each line represents the state of the buffer and semaphores after the scheduled execution has occurred. Each semaphore maintains a FIFO (first-in-first-out) queue of blocked processes. There are multiple producer processes, referred to as Pa, Pb, Pc, etc., and multiple consumer processes, referred to as Ca, Cb, Cc, etc. Semaphores empty and full are linear semaphores that can take unbounded negative and positive values. ![]() Labels p1, p2, p3 and c1, c2, c3 refer to the lines of code shown above (p2 and c2 each cover three lines of code). The following pseudocode is a correct implementation of the producer/consumer problem with a bounded buffer: item buffer // initially empty semaphore empty // initialized to +3 semaphore full // initialized to O binary semaphore mutex // initialized to 1 void producer void consumer while (true) ![]()
0 Comments
Leave a Reply. |