pthread09.c 591 B

123456789101112131415161718192021222324252627282930313233
  1. #include "unpthread.h"
  2. #include "pthread09.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. socklen_t clilen;
  16. struct sockaddr *cliaddr;
  17. cliaddr = Malloc(addrlen);
  18. printf("thread %d starting\n", (int) arg);
  19. for ( ; ; ) {
  20. clilen = addrlen;
  21. connfd = Accept(listenfd, cliaddr, &clilen);
  22. tptr[(int) arg].thread_count++;
  23. web_child(connfd); /* process the request */
  24. Close(connfd);
  25. }
  26. }