void worker_function (struct server *sv) { while(1) { //pthread_cond_wait(&BLOCK,&lock); int connfd2 = process(sv); do_server_request(sv,connfd2); } }
void server_request(struct server *sv, int connfd) { if (sv->nr_threads == 0) { /* no worker threads */ do_server_request(sv, connfd); } else { fill_in(sv, connfd); //pthread_cond_signal(&BLOCK); /* Save the relevant info in a buffer and have one of the * worker threads do the work. */ } }
void *thread_pool(void *sv){ while(1){ pthread_mutex_lock( &conditionMutex ); struct server *my_sv = (struct server*)sv; while(ready_queue == NULL) pthread_cond_wait(&Notempty,&conditionMutex); int connfd = ready_queue->key; if(counter>=buffer_max) pthread_cond_signal( &Notfull ); ready_queue = delete_head(ready_queue); // delete it from the queue pthread_mutex_unlock( &conditionMutex ); do_server_request(my_sv, connfd); } return NULL; }
void server_request(struct server *sv, int connfd) { if (sv->nr_threads == 0) { /* no worker threads */ do_server_request(sv, connfd); } else { /* Save the relevant info in a buffer and have one of the * worker threads do the work. */ pthread_mutex_lock( &conditionMutex ); while(counter>=buffer_max) pthread_cond_wait(&Notfull, &conditionMutex); if(ready_queue == NULL) pthread_cond_signal(&Notempty); ready_queue =put_at_tail(ready_queue, connfd); pthread_mutex_unlock(&conditionMutex); } }