delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/08/02/14:49:38

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Subject: pthread_create and priorities
To: cygwin AT cygwin DOT com
X-Mailer: Lotus Notes Release 5.0.7 March 21, 2001
Message-ID: <OFE5BEA8FF.569DAB4A-ON85256A9C.0065FA13@raleigh.ibm.com>
From: "Timothy Gee" <timmygee AT us DOT ibm DOT com>
Date: Thu, 2 Aug 2001 14:49:28 -0400
X-MIMETrack: Serialize by Router on D04NMS21/04/M/IBM(Release 5.0.6 |December 14, 2000) at
08/02/2001 02:48:03 PM
MIME-Version: 1.0

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 AT OLE300GL /home/testy/FW_test
$ gcc schedTest.c

Administrator AT 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 AT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019