There is a very specific question, but I was thinking that a consumer is having a problem catching the first consumer {Pthread_cond_init (and condVars [i], NULL), with many consumers, for the manufacturer relationship (HTTP web server)
(i = 0; i & lt; num_threads; i ++) ; If (SRCMP (policy, "fifo") == 0) pthread_create (& threadArr [i], zero, worker, FIFO, and condVars [i]); Otherwise pthread_create (and threads ARR [i], NULL, worker sff, and condVars [i]); } Listenfd = open_listenfd (port); // Producer while (1) {clientlen = sizeof (clientaddr); Connfd = Accept (listenfd, (SA *) and Client Aid, (Socon_T *) and Client Lion); Pthread_mutex_lock (& amp; mutex); Whereas (numRequests == num_buffers) pthread_cond_wait (& amp; empty, and mutex); If (strcode (policy, "fifo") == 0) putFIFO (connfd); And put SSFF (connfd); NumRequests ++; Pthread_cond_signal (nextWorker);; NextWorker = (Next + 1)% num_threads; Pthread_mutex_unlock (& amp; amp; mutex); Printf ("% s \ n", "Do not Watch Dead !!!"); } // Consumer Time (1) {pthread_mutex_lock (& amp; mutex); Whereas (numRequests == 0) {printf ("% u \ n", condVar); Pthread_cond_wait (condVar, and mutex); Printf ("% s", "caught"); } Printf ("% s,% u \ n", "Its working!!!!!", Kandavi); Int connfd = buffer [nextOutFIFO]; NextOutFIFO = (nextoffiff + 1)% num_buffers; NumRequests--; Pthread_cond_signal (& amp; down); Pthread_mutex_unlock (& amp; amp; mutex); RequestHandle (connfd); Off (connfd); }
I do not believe the problem is solved in the last reply, because both The operation is being performed inside the important section.
I would recommend using a counting semaphore instead of an integer for numRequests
. The manufacturer does a sem_post ()
and the consumer performs a sem_wait ()
. The first consumer coming back from the waiting will reduce the sequester and then lock Mute X only when modifying the shared variables, reduce the code within the important section, and put the sense of command Which is not provided by muiting alone.
No comments:
Post a Comment