samkitjain / producer-consumer-posix-code Goto Github PK
View Code? Open in Web Editor NEWConsider a system comprising of two producer processes, one consumer process, and two buffers as shown above. The size of each buffer is 10. Each producer process randomly creates a specific colored item: Producer_Red creates red colored items, and Producer_Blue creates blue-colored items. Each producer deposits its item in any one of the two buffers, whichever has space available. If both buffers have space available, then one of them is selected arbitrarily.. Associated with each item created by a specific producer is a local UNIX timestamp in microseconds (use the gettimeofday() function) which records the time that item was placed in the buffer. The items produced by the producers will be two strings of the form shown below: “RED unix_timestamp” or “BLUE unix_timestamp” Each producer process, after successfully depositing an item in the buffer, will write that item (essentially the “COLOR Unix_timestamp” string) to its log file called Producer_COLOR.txt (e.g. Producer_RED.txt). The consumer retrieves an item from whichever buffer an item is available, and writes it to a file named “Consumer.txt”.