Try moving the kill thread code into the thread_main() function so it can
check if there are too many thread after it's finished with it's request. Needs to be cleaned up further (if this is the right idea) because of the locking around the servers_waiting variable.
This commit is contained in:
		
							parent
							
								
									445aaca53e
								
							
						
					
					
						commit
						f2312262c7
					
				
							
								
								
									
										32
									
								
								src/thread.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								src/thread.c
									
									
									
									
									
								
							@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: thread.c,v 1.9 2001-09-06 19:00:47 rjkaes Exp $
 | 
					/* $Id: thread.c,v 1.10 2001-09-06 21:16:35 rjkaes Exp $
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Handles the creation/destruction of the various threads required for
 | 
					 * Handles the creation/destruction of the various threads required for
 | 
				
			||||||
 * processing incoming connections.
 | 
					 * processing incoming connections.
 | 
				
			||||||
@ -140,6 +140,16 @@ static void *thread_main(void *arg)
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (servers_waiting > thread_config.maxspareservers) {
 | 
				
			||||||
 | 
								/*
 | 
				
			||||||
 | 
								 * There are too many spare threads, kill ourselves
 | 
				
			||||||
 | 
								 * off.
 | 
				
			||||||
 | 
								 */
 | 
				
			||||||
 | 
								log_message(LOG_NOTICE, "Too many spare threads, killing ourself.");
 | 
				
			||||||
 | 
								ptr->status = T_EMPTY;
 | 
				
			||||||
 | 
								return NULL;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ptr->status = T_WAITING;
 | 
							ptr->status = T_WAITING;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		SERVER_INC();
 | 
							SERVER_INC();
 | 
				
			||||||
@ -195,8 +205,8 @@ int thread_pool_create(void)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Keep the proper number of servers running. This is the birth and death
 | 
					 * Keep the proper number of servers running. This is the birth of the
 | 
				
			||||||
 * of the servers. It monitors this at least once a second.
 | 
					 * servers. It monitors this at least once a second.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int thread_main_loop(void)
 | 
					int thread_main_loop(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -216,22 +226,6 @@ int thread_main_loop(void)
 | 
				
			|||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if (servers_waiting > thread_config.maxspareservers) {
 | 
					 | 
				
			||||||
		DEBUG2("servers_waiting: %d MaxSpareServers: %d", servers_waiting, thread_config.maxspareservers);
 | 
					 | 
				
			||||||
		for (i = 0; i < thread_config.maxclients; i++) {
 | 
					 | 
				
			||||||
			if (thread_ptr[i].status == T_WAITING) {
 | 
					 | 
				
			||||||
				pthread_join(thread_ptr[i].tid, NULL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				SERVER_DEC();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				thread_ptr[i].status = T_EMPTY;
 | 
					 | 
				
			||||||
				thread_ptr[i].connects = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				log_message(LOG_NOTICE, "Killed off a thread.");
 | 
					 | 
				
			||||||
				break;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		DEBUG1("finished killing threads");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user