pthread08.c 685 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "unpthread.h"
  2. #include "pthread08.h"
  3. void
  4. thread_make(int i)
  5. {
  6. void *thread_main(void *);
  7. Pthread_create(&tptr[i].thread_tid, NULL, &thread_main, (void *) i);
  8. return; /* main thread returns */
  9. }
  10. void *
  11. thread_main(void *arg)
  12. {
  13. int connfd;
  14. void web_child(int);
  15. printf("thread %d starting\n", (int) arg);
  16. for ( ; ; ) {
  17. Pthread_mutex_lock(&clifd_mutex);
  18. while (iget == iput)
  19. Pthread_cond_wait(&clifd_cond, &clifd_mutex);
  20. connfd = clifd[iget]; /* connected socket to service */
  21. if (++iget == MAXNCLI)
  22. iget = 0;
  23. Pthread_mutex_unlock(&clifd_mutex);
  24. tptr[(int) arg].thread_count++;
  25. web_child(connfd); /* process request */
  26. Close(connfd);
  27. }
  28. }