Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > pthread > pthread__k_tuple__async
diff src/Application/producer.c @ 1:88db7b62b961
Working queue based version
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Wed, 10 Jul 2013 14:17:04 -0700 |
| parents | 9cf9b2091eeb |
| children |
line diff
1.1 --- a/src/Application/producer.c Wed Jul 10 14:13:46 2013 -0700 1.2 +++ b/src/Application/producer.c Wed Jul 10 14:17:04 2013 -0700 1.3 @@ -10,8 +10,6 @@ 1.4 * Producer. 1.5 * 1.6 * Birth function for thread that performs the producer behavior 1.7 - * 1.8 - * Note: is pinned to a core, to facilitate collecting measurements 1.9 */ 1.10 void* 1.11 producer_birthFn( void* _params ) 1.12 @@ -22,7 +20,6 @@ 1.13 ProducerParams *params = (ProducerParams *)_params; 1.14 1.15 lastTupleIter = 0; //compared to global tupleIter while waiting 1.16 - oldConsumerReceivedACKNum = 0; //used when waiting for consumer to receive 1.17 1.18 /* -------------------------------------------------- 1.19 * Pin thread to core, the producers are divided 1.20 @@ -44,12 +41,9 @@ 1.21 1.22 /*Protocol: 1.23 * wait for change in tupleIter (save updated tuple num for next time) 1.24 - * Get producer lock (only one producer at a time) 1.25 - * write into comm vars 1.26 - * get current ACK number 1.27 - * notify consumer 1.28 - * wait for ACK (get ACK lock, check on change in ACK number) 1.29 - * release producer lock 1.30 + * Get queue lock 1.31 + * write into queue 1.32 + * release queue lock 1.33 * if not done, repeat 1.34 */ 1.35 while( lastTupleIter < params->numTuplesToCreate ) 1.36 @@ -61,46 +55,18 @@ 1.37 pthread_cond_wait( &tupleIterCond, 1.38 &tupleIterLock ); 1.39 } 1.40 - pthread_mutex_unlock( &tupleIterLock ); 1.41 + pthread_mutex_unlock( &tupleIterLock ); 1.42 1.43 lastTupleIter = tupleIter; //save for next time through loop 1.44 1.45 DEBUG__printf2("Producer: %d starting tuple: %d\n", params->producerID, tupleIter); 1.46 1.47 - //Two vars used to comm with consumer. One holds message to send, 1.48 - // other holds ID of producer sending. 1.49 - //Protect the two variables with a lock, that only one 1.50 - // producer can get. Update the variable with the message to be 1.51 - // communicated, and write ID of sender in second var. 1.52 + //Q used to comm with consumer, protected with a lock 1.53 1.54 //Get producer lock 1.55 - pthread_mutex_lock( &producerAccessMutex ); 1.56 - 1.57 - // write into comm vars 1.58 - producerMessage = tupleIter; //just a dummy -- overhead meas, do nothing 1.59 - currProductionNum += 1; 1.60 - 1.61 - // get current ACK number 1.62 - oldConsumerReceivedACKNum = currConsumerReceivedACKNum; 1.63 - 1.64 - // notify consumer (don't think need the cond lock here -- teeter-totter) 1.65 - pthread_mutex_lock( &productionReadyLock ); 1.66 - DEBUG__printf1("producer %d wrote msg, about to wake up consumer\n", params->producerID ); 1.67 - pthread_cond_broadcast( &productionReadyCond ); 1.68 - pthread_mutex_unlock( &productionReadyLock ); 1.69 - 1.70 - // wait for ACK (get ACK lock, check on change in ACK number) 1.71 - pthread_mutex_lock( &consumerReceivedAckLock ); 1.72 - while( currConsumerReceivedACKNum == oldConsumerReceivedACKNum ) 1.73 - { 1.74 - pthread_cond_wait( &consumerReceivedAckCond, 1.75 - &consumerReceivedAckLock ); 1.76 - } 1.77 - pthread_mutex_unlock( &consumerReceivedAckLock ); 1.78 - DEBUG__printf2("producer %d got ack %d\n", params->producerID, currConsumerReceivedACKNum ); 1.79 - 1.80 - // release producer lock (so different producer can get and send) 1.81 - pthread_mutex_unlock( &producerAccessMutex ); 1.82 + pthread_mutex_lock( &queueAccessLock ); 1.83 + writePrivQ( params, commQ ); //params is just a dummy pointer 1.84 + pthread_mutex_unlock( &queueAccessLock ); 1.85 } //if not done, do again 1.86 1.87 //Shutdown producer
