Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Apr 1998 19:19:36 +0200 (CEST)
From:      lada@pc8811.gud.siemens.at
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/6467: Thread incremental priority update
Message-ID:  <199804301719.TAA29819@pc8811.gud.siemens.at>

next in thread | raw e-mail | index | archive | help

>Number:         6467
>Category:       bin
>Synopsis:       Thread incremental priority update
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 30 10:20:01 PDT 1998
>Last-Modified:
>Originator:     lada@pc8811.gud.siemens.at
>Organization:
>Release:        FreeBSD 2.2.6-RELEASE i386
>Environment:


>Description:
The code in question increased the priority of runnable thread only if
it became inactive after the last priority update.  This means that
the priority boost was added at most once to any inactive thread.

>How-To-Repeat:

the test program (test.c) follows;
it was compiled with 
	cc test.c -o test -lc_r

#define _THREAD_SAFE
#define DO_YIELD
#define DO_YIELD2
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>

void *writer( void *arg )
{
	int i = 0;
	int j;

	for (;; i++) 
		switch (i%7) {
		case 0:	puts( "One" );
			break;
		case 1:	puts( "Two" );
			break;
		case 2:	for (j=0; j<10000000;)
				j++;
			puts( "Three" );
			break;
		case 3:	puts( "Four" );
			break;
		case 4:	puts( "Five" );
			break;
		case 5:	puts( "Six" );
			break;
		case 6:	puts( "Seven" );
#ifdef DO_YIELD
			pthread_yield();
			puts( "Yield in writer returned" );
#endif
			break;
		}

	return NULL;
}

void *looper( void *arg )
{
	long int i = 0;

	for (;;) {
		if (i==10000000) {
			puts( "Yielding" );
#ifdef DO_YIELD2
			pthread_yield();
#endif
			puts( "Yield returned" );
			i = 0;
		}
		else 
			i++;
	}

	return NULL;
}

int main (void)
{

	pthread_t	printer, cpu_hog;
	void 		*result;

	pthread_create( &printer, pthread_attr_default, writer, "first" );
 	pthread_create( &cpu_hog, pthread_attr_default, looper, "second" ); 

	pthread_join( printer, &result );

	return 0;
}



>Fix:

This patch seems to fix this (i.e. both threads get to run), but there
are still some other problems: if DO_YIELD's are not defined only one
of the threads seems to be running.  This will require further investigation.
	

--- uthread_kern.c	1998/04/30 16:31:53	1.1
+++ uthread_kern.c	1998/04/30 16:34:33
@@ -349,7 +349,7 @@
 				 * the last incremental priority check was
 				 * made: 
 				 */
-				else if (timercmp(&_thread_run->last_inactive, &kern_inc_prio_time, >)) {
+				else if (timercmp(&_thread_run->last_inactive, &kern_inc_prio_time, <)) {
 					/*
 					 * Increment the incremental priority
 					 * for this thread in the hope that
>Audit-Trail:
>Unformatted:
Marino Ladavac

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199804301719.TAA29819>