Untitled
unknown
plain_text
a month ago
1.2 kB
1
Indexable
Never
// Each producer enqueues `np` items where np=n/nProducers except for producer 0 long item = 0; long items_produced = 0; long value_produced = 0; while(items_produced < np) { bool ret = production_buffer.enqueue(item); //item includes value and type if(ret == true) { if(production_buffer.itemCount() == 1){ // The queue is no longer empty // Signal all consumers indicating queue is not empty } value_produced += item; items_produced++; item++; // also update item count and value for item type produced } else { // production_buffer is full, so block on conditional variable waiting for consumer to signal. } } // After production is completed: // Update the number of producers that are currently active. --active_producer_count; // The producer that was last active (can be determined using `active_producer_count`) will keep signalling the consumers until all consumers have finished (can be determined using `active_consumer_count`).
Leave a Comment