This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

pthread_create and priorities


I have looked through the achieves and haven't seen this addressed.

I want to start up a pthread with a given priority. The documentation seems
clear enough, however, the code I wrote doesn't work. The thread always
starts with a default priority. I can use a similar procedure within the
thread to adjust priority and that works. What have I overlooked? I am
running DLL 1.3.2 on Win NT (Patch 5.0, I believe).

THE CODE:
******** FILE: schedTest.c ******************

#include <pthread.h>

char *sched_type[] = {
    "SCHED_OTHER",
    "SCHED_FIFO",
    "SCHED_RR"
};

void pthread_info(void){
    pthread_t thread;
    struct sched_param sp;
    int type;
    int rc;
    thread = pthread_self();
    rc=pthread_getschedparam(thread, &type, &sp);
    printf("Thread id:%x %s Priority Max:%d, Current:%d, Min:%d\n",
           thread,
           sched_type[type],
           sched_get_priority_max(type),
           sp.sched_priority,
           sched_get_priority_min(type));
}

pthread_t t1;
void mytest(void) {
    puts("Mytest1");
    /*print thread info*/
    pthread_info();
}


int main(void) {
    pthread_attr_t attr;
    struct sched_param parm;
    puts("Hello world!");
    pthread_attr_init(&attr);
    parm.sched_priority=-3;
    pthread_attr_setschedpolicy(&attr,SCHED_FIFO);
    pthread_attr_setschedparam(&attr,&parm);
    pthread_create(&t1, &attr, (void *) mytest, NULL);
    puts("That's all folks");
    pthread_join(t1,NULL);
    return 0;
}

THE OUTPUT:
**************************
Administrator@OLE300GL /home/testy/FW_test
$ gcc schedTest.c

Administrator@OLE300GL /home/testy/FW_test
$ a
Hello world!
That's all folks
Mytest1
Thread id:a010500 SCHED_FIFO Priority Max:-14, Current:0, Min:15
*******************************************************^****************
********************************************should be -3 instead . . . .
************************************************************************

Administrator@OLE300GL /home/testy/FW_test
$

Thanks . . .
-Tim-
Dept DGBA
K115/062
(919) 543-0921


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]