Hi,

I`m new to Xenomai and I`m experiencing some issues.

Why does a Xenomai thread (native skin) with an infinite loop hang the system, 
though there are higher-priority RT-threads present, and
rt_task_set_mode periodically clears T_LOCK and T_SHIELD and sets T_RRB?

Isn`t the scheduler preemptive, first considering the thread`s priority and 
subsequently the thread`s position in its priority`s ready queue?

I have attached some sample code.

Thanks for any hint,

Jack


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <sys/types.h>

#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/timer.h>


#define STACK_SIZE 8192
#define PRIO 10


static RT_TASK timer_task_desc;

//                            ..s.ms.µs.ns
static RTIME task_period_ns =   0100000000llu;

static unsigned long overruns = 0;

static void clean_exit(int dummy) {

  rt_task_delete(&timer_task_desc);

}

static void thread(void *cookie) {

  int ret;
  int i;
  int c;


  ret = rt_task_set_mode(T_LOCK, T_RRB, &c);
  if (ret)
    return;

  ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns));
  if (ret)
    return;

  while (1) {
    
    ret = rt_task_set_mode(T_LOCK | T_SHIELD, T_RRB | T_PRIMARY, NULL);
    if (ret)
      return;

    ret = rt_task_wait_period(&overruns);
    if (ret == -ETIMEDOUT) {
    } else if (ret) {
      clean_exit(0);
    }

    while (1);  /* infinite loop */

  }
  kill(0, SIGTERM);
}


int main(int argc, char** argv) {

  int err;

  signal(SIGTERM, clean_exit);
  signal(SIGINT, clean_exit);

  mlockall(MCL_CURRENT | MCL_FUTURE);

  err = rt_task_spawn(&timer_task_desc, "thread", STACK_SIZE, PRIO, 0, &thread, 
NULL);
  if (err)
    return 0;

  pause();

  return EXIT_SUCCESS;

}
-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail

_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to