Advance operating system

    Process Synchronization: Producer-Consumer Problem The purpose of this programming activity is to analyze action synchronization. This will be able by autograph a affairs on the Ambassador / Customer botheration declared below. Your simulation will be implemented application Pthreads. This appointment is a modification to the programming activity “The Ambassador – Customer Problem” begin at the end of Affiliate 7 of our textbook. 1. Your affairs charge be accounting application C or C++ and you are appropriate to use the Pthread with mutex and semaphore libraries. In affiliate 3, we discussed how a "bounded buffer" could be acclimated to accredit ambassador and customer processes to allotment memory. We declared a address application a annular absorber that can authority BUFFER_SIZE-1 items. By application a aggregate anamnesis area count, the absorber can authority all BUFFER_SIZE items. This calculation is initialized to 0 and is incremented every time an account is placed into the absorber and decremented every time an account is removed from the buffer. The calculation abstracts account can additionally be implemented as a counting semaphore. The ambassador can abode items into the absorber alone if the absorber has a chargeless anamnesis area to abundance the item. The ambassador cannot add items to a abounding buffer. The customer can abolish items from the absorber if the absorber is not empty. The customer charge delay to absorb items if the absorber is empty. The "items" stored in this absorber will be integers. Your ambassador action will accept to admit accidental numbers into the buffer. The customer action will absorb a number. Assignment Specifications The absorber acclimated amid ambassador and customer processes will abide of a fixed-size arrangement of blazon buffer_item. The chain of buffer_item altar will be manipulated application a annular array. The absorber will be manipulated with two functions, buffer_insert_item() and buffer_remove_item(), which are alleged by the ambassador and customer threads, respectively. A skeleton analogue these functions can be begin in buffer.h (provided below). Skeleton analogue (Buffer.h) #ifndef _BUFFER_H_DEFINED_ #define _BUFFER_H_DEFINED_ typedef int buffer_item; #define BUFFER_SIZE 5 bool buffer_insert_item( buffer_item account ); bool buffer_remove_item( buffer_item *item ); #endif // _BUFFER_H_DEFINED_ The buffer_insert_item() and buffer_remove_item() functions will accord the ambassador and customer application the algorithms. The absorber will additionally crave an initialization action (not     supplied in buffer.h) that initializes the alternating exclusion article "mutex" forth with the "empty" and "full" semaphores. The ambassador cilia will alternating amid sleeping for a accidental aeon of time and breeding and inserting (trying to) an accumulation into the buffer. Accidental numbers will be generated application the rand_r() function. See the argument on folio 290 for an overview of the ambassador algorithm. The customer cilia will alternating amid sleeping for a accidental aeon of time (thread safe of course) and (trying to) removing a cardinal out of the buffer. See the argument on folio 290 for an overview of the customer algorithm. The capital action will initialize the absorber and actualize the abstracted ambassador and customer threads. Once it has created the ambassador and customer threads, the main() action will sleep for continuance of the simulation. Upon awakening, the capital cilia will arresting alternative accoutrement to abdicate by ambience a simulation banderole which is a all-around variable. The capital cilia will accompany with the alternative accoutrement and again affectation the simulation statistics. The main() action will be anesthetized two ambit on the command line: • The breadth of time the capital cilia is to beddy-bye afore absolute (simulation breadth in seconds) • The best breadth of time the ambassador and customer accoutrement will beddy-bye above-mentioned to bearing or arresting a buffer_item A skeleton for the capital action appears as: #include <buffer.h> int main( int argc, burn *argv[] ){ Get command band arguments Initialize buffer Create ambassador thread(s) Actualize customer thread(s) Sleep Join Threads Display Statistics Exit } Creating Pthreads application the Pthreads API is discussed in Affiliate 4 and in Assignment-1. Please accredit to those references for specific instructions apropos conception of the ambassador and consumer Pthreads.     The afterward cipher sample illustrates how mutex locks accessible in the Pthread API can be acclimated to assure a analytical section: #include <pthread.h> pthread_mutex_t mutex; /* actualize the mutex lock */ pthread_mutex_init( &mutex, NULL ); /* aquire the mutex lock */ pthread_mutex_lock( &mutex ); /*** CRITICAL SECTION ***/ /* absolution the mutex lock */ pthread_mutex_unlock( &mutex ); Pthreads uses the pthread_mutex_t abstracts blazon for mutex locks. A mutex is created with the pthread_mutex_init() function, with the aboriginal constant actuality a arrow to the mutex. By casual NULL as a additional parameter, we initialize the mutex to its absence attributes. The mutex is acquired and appear with the pthread_mutex_lock() and pthread_mutex_unlock() functions. If the mutex lock is bare back pthread_mutex_lock() is invoked, the calling cilia is blocked until the buyer invokes pthread_mutex_unlock(). All mutex functions acknowledgment a amount of 0 with actual operation; if an absurdity occurs, these functions acknowledgment a nonzero absurdity code. Pthreads provides two types of semaphores: called and unnamed. For this project, we will use bearding semaphores. The cipher beneath illustrates how a semaphore is created: #include <semaphore.h> sem_t sem; /* actualize the semaphore and initialize it to 5 */ sem_init( &sem, 0, 5 ); The sem_init() action creates and initializes a semaphore. This action is anesthetized three parameters: A arrow to the semaphore, a banderole advertence the akin of sharing, and the semaphore's antecedent value. In this example, by casual the banderole 0, we are advertence that this semaphore can alone be aggregate by accoutrement acceptance to the aforementioned action that created the semaphore. A nonzero amount would acquiesce alternative processes to admission the semaphore as well. In this example, we initialize the semaphore to the amount 5.    In Chapter-6 (Section 6.6), we declared the classical wait() and signal() semaphore operations. Pthread names the wait() and signal() operations sem_wait() and sem_post(), respectively. The cipher archetype beneath creates a bifold semaphore mutex with an antecedent amount 1 and illustrates it use in attention a analytical section: #include <semaphore.h> sem_t mutex; /* actualize the semaphore */ sem_init( &mutex, 0, 1 ); /* access the semaphore */ sem_wait( &mutex ); /*** CRITICAL SECTION ***/ /* absolution the semaphore */ sem_post( &mutex ); Program Output Your simulation should achievement back assorted altitude occur: absorber empty/full, area of producer/consumer, etc. Submission Guidelines and Requirements 1. Your affairs charge be accounting application C or C++ and you are appropriate to use the Pthread with mutex and semaphore libraries 2. You may use the C/C++ STL (Standard Template Library) in your solution. 3. You should use Netbeans to apparatus the assignment. You can download Netbeans with C/C++ appearance from the afterward link: https://netbeans.org/downloads/8.2/ 4. Actualize activity in Netbeans for commutual this assignment. 5. Add comments (about the function/variable/class) to your cipher as abundant as possible 6. Zip your activity including antecedent files and input/output argument abstracts files (if any) 7. Upload the ambiguous activity book assimilate Blackboard

Order a unique copy of this paper

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
Top Academic Writers Ready to Help
with Your Research Proposal
Order now and a get a 25% discount with the discount code: COURSEGUYOrder Now!
+ +