Multitasking with priority problem

Gedare Bloom gedare at gwmail.gwu.edu
Wed Sep 14 22:49:13 UTC 2011


Hi,

attr->inheritsched is PTHREAD_INHERIT_SCHED by default. See below for the fix.

Good luck!
Gedare

On Thu, Sep 8, 2011 at 11:25 AM, Inderjit Singh
<inderjit.singh at spaceapplications.com> wrote:
> Hi,
>
> I'm running RTEMS 4.10 on Gaisler-RASTA platform with Leon2 processor.
>
> I'm trying to run 2 tasks with priorities but failing to get my code to
> work. The code is:
>
> --------------
> #include <rtems.h>
> #include <bsp.h> /* for device driver prototypes */
> #include <pthread.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> #define CONFIGURE_INIT_TASK_ENTRY_POINT   POSIX_Init
>
> pthread_t task_2_id;
>
> void* task_2(void* arg)
> {
>     int type;
>     struct sched_param sch_params;
>     pthread_getschedparam(task_2_id, &type, &sch_params);
>     while(1)
>     {
>          printf("TASK 2 priority: %d\n", sch_params.sched_priority);
>         sleep(1);
>     }
> }
>
> //rtems_task Init(rtems_task_argument
> ignored)
> //void*
> POSIX_Init()
> void *POSIX_Init(void *argument)
>
> {
>     int type;
>     int status;
>     pthread_attr_t attr;
>     struct sched_param sch_params;
>
>     pthread_attr_init(&attr);
>     sch_params.sched_priority = 100;
>     pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
>     pthread_attr_setschedparam(&attr,&sch_params);
    pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
>
>     /* Main task with priority */
>     status = pthread_create(&task_2_id,
>                             &attr,
>                             task_2,
>                             NULL);
>     printf("Status: %d\n", status);
>
>     pthread_getschedparam(pthread_self(), &type, &sch_params);
>
>     while(1)
>     {
>          printf("Maint task priority: %d\n", sch_params.sched_priority);
>     sleep(1);
>     }
>
>     exit(0);
> }
>
> #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
> #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
> #define CONFIGURE_MAXIMUM_POSIX_THREADS                         4
> #define CONFIGURE_POSIX_INIT_THREAD_TABLE
> /* #define CONFIGURE_MAXIMUM_TASKS             4 */
>
> /* #define CONFIGURE_RTEMS_INIT_TASKS_TABLE */
>
> /* #define CONFIGURE_EXTRA_TASK_STACKS         (3 *
> RTEMS_MINIMUM_STACK_SIZE) */
>
> /* configuration information */
> #define CONFIGURE_INIT
> #include
> <confdefs.h>
> --------------
>
> But at the console I get:
> -------------
> Status: 0
> Maint task priority: 2
> TASK 2 priority: 2
> Maint task priority: 2
> TASK 2 priority: 2
> Maint task priority: 2
> TASK 2 priority: 2
> -------------
>
> Can some one point me to the right direction why. Thanks,
> Indy
> ________________________________________
> Inderjit Singh
> Software Engineer
> Avionics & Embedded Systems
> Email: inderjit.singh at spaceapplications.com
>
> Space Applications Services
> Leuvensesteenweg 325
> B-1932 Zaventem
> Belgium
> Direct Tel: +32-(0)2-416.05.27
> Fax: +32 (0)2-721.54.44
> Please consider the environment before printing this email
>
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-users
>
>




More information about the users mailing list