1 #include	"unpthread.h"
2 #include	"pthread07.h"
3 
4 void
thread_make(int i)5 thread_make(int i)
6 {
7 	void	*thread_main(void *);
8 
9 	Pthread_create(&tptr[i].thread_tid, NULL, &thread_main, (void *) i);
10 	return;		/* main thread returns */
11 }
12 
13 void *
thread_main(void * arg)14 thread_main(void *arg)
15 {
16 	int				connfd;
17 	void			web_child(int);
18 	socklen_t		clilen;
19 	struct sockaddr	*cliaddr;
20 
21 	cliaddr = Malloc(addrlen);
22 
23 	printf("thread %d starting\n", (int) arg);
24 	for ( ; ; ) {
25 		clilen = addrlen;
26     	Pthread_mutex_lock(&mlock);
27 		connfd = Accept(listenfd, cliaddr, &clilen);
28 		Pthread_mutex_unlock(&mlock);
29 		tptr[(int) arg].thread_count++;
30 
31 		web_child(connfd);		/* process the request */
32 		Close(connfd);
33 	}
34 }
35