FreeBSD/tools/regression/gaithrstress/gaithrstress.c
/*
 * Start looking up arbitrary hostnames and record the successes/failures.
 * Between lookups, sleep a random amount of time to make sure threads
 * stay well out of synchronization.
 *
 * Host name:	part		probability
 *		----		-----------
 *		www.		1/2
 *		random word	always, equal
 *		random word	1/3, equal
 *		.(net|com|org)	equal
 */
Start looking up arbitrary hostnames and record the successes/failures.
Between lookups, sleep a random amount of time to make sure threads
stay well out of synchronization.

Host name:   part            probability

www.            1/2
random word     always, equal
random word     1/3, equal
.(net|com|org)  equal
Start looking up arbitrary hostnames and record the successes / failures . Between lookups sleep a random amount of time to make sure threads stay well out of synchronization . Host name : part probability www . 1 / 2 random word always equal random word 1 / 3 equal . ( net|com|org ) equal
static void *
work(void *arg)
{
	struct worker *w = arg;
	if (_res.options & RES_INIT || res_init() == 0)
		_res.options &= ~RES_DNSRCH;
	do {
		const char *suffixes[] = { "net", "com", "org" };
		const size_t nsuffixes = sizeof(suffixes) / sizeof(suffixes[0]);
		struct timespec ts_begintime, ts_total;
		struct addrinfo *res;
		char *hostname;
		int error;
		randomsleep(max_random_sleep);
		if (asprintf(&hostname, "%s%s%s.%s",
		    (my_arc4random_r() % 2) == 0 ? "www." : "",
		    randwords[my_arc4random_r() % nrandwords],
		    (my_arc4random_r() % 3) == 0 ?
		    randwords[my_arc4random_r() % nrandwords] : "",
		    suffixes[my_arc4random_r() % nsuffixes]) == -1)
			continue;
		(void)clock_gettime(CLOCK_REALTIME, &ts_begintime);
		error = getaddrinfo(hostname, NULL, hints, &res);
		(void)clock_gettime(CLOCK_REALTIME, &ts_total);
		ts_total.tv_sec -= ts_begintime.tv_sec;
		ts_total.tv_nsec -= ts_begintime.tv_nsec;
		if (ts_total.tv_nsec < 0) {
			ts_total.tv_sec--;
			ts_total.tv_nsec += 1000000000;
		}
		if (ts_total.tv_sec > w->w_max_lookup_time.tv_sec ||
		    (ts_total.tv_sec == w->w_max_lookup_time.tv_sec &&
		    ts_total.tv_nsec > w->w_max_lookup_time.tv_sec))
			w->w_max_lookup_time = ts_total;
		free(hostname);
		if (error == 0) {
			w->w_lookup_success++;
			freeaddrinfo(res);
		} else {
			w->w_lookup_failure++;
		}
	} while (!workers_stop);
	pthread_exit(NULL);
}
static void * work ( void * arg ) { struct worker * w = arg ; if ( _res . options & RES_INIT || res_init ( ) == 0 ) _res . options &= ~ RES_DNSRCH ; do { const char * suffixes [ ] = { " " , " " , " " } ; const size_t nsuffixes = sizeof ( suffixes ) / sizeof ( suffixes [ 0 ] ) ; struct timespec ts_begintime , ts_total ; struct addrinfo * res ; char * hostname ; int error ; randomsleep ( max_random_sleep ) ; if ( asprintf ( & hostname , " " , ( my_arc4random_r ( ) % 2 ) == 0 ? " " : " " , randwords [ my_arc4random_r ( ) % nrandwords ] , ( my_arc4random_r ( ) % 3 ) == 0 ? randwords [ my_arc4random_r ( ) % nrandwords ] : " " , suffixes [ my_arc4random_r ( ) % nsuffixes ] ) == -1 ) continue ; ( void ) clock_gettime ( CLOCK_REALTIME , & ts_begintime ) ; error = getaddrinfo ( hostname , NULL , hints , & res ) ; ( void ) clock_gettime ( CLOCK_REALTIME , & ts_total ) ; ts_total . tv_sec -= ts_begintime . tv_sec ; ts_total . tv_nsec -= ts_begintime . tv_nsec ; if ( ts_total . tv_nsec < 0 ) { ts_total . tv_sec -- ; ts_total . tv_nsec += 1000000000 ; } if ( ts_total . tv_sec > w -> w_max_lookup_time . tv_sec || ( ts_total . tv_sec == w -> w_max_lookup_time . tv_sec && ts_total . tv_nsec > w -> w_max_lookup_time . tv_sec ) ) w -> w_max_lookup_time = ts_total ; free ( hostname ) ; if ( error == 0 ) { w -> w_lookup_success ++ ; freeaddrinfo ( res ) ; } else { w -> w_lookup_failure ++ ; } } while ( ! workers_stop ) ; pthread_exit ( NULL ) ; }
Start looking up arbitrary hostnames and record the successes/failures.
Start looking up arbitrary hostnames and record the successes / failures .
/* Turn off domain name list searching as much as possible. */