I was happy to see that printf now works from real-time POSIX threads in Xenomai 2.6.0.  
Unfortunately, I'm seeing some strange behavior that surfaces when I try to print the 
string "\n" by itself.  When I run the attached example program, I get:

  $ ./printf_test
  start
  CPU time limit exceeded
  $

IfI replace the two printf calls with rt_printf calls and #include <rtdk.h>,I 
get the expected result:

  $ ./rt_printf_test
  start
  1
  2
  3
  4
  ^C
  $

The original example also works if these two lines:

        printf("%d", count);
        printf("\n");

are replaced with:

        printf("%d\n", count);

Can someone confirm if this a bug in Xenomai 2.6.0, something specific to my 
HW/SW installation, or some mistake in my test program?

Thanks,

Jeff
#include <stdio.h>
#include <pthread.h>
#include <sys/mman.h>
#include <malloc.h>

int count = 0;

void * rt_loop(void * arg)
{
    struct timespec dt_ts;
    dt_ts.tv_sec  = 1;
    dt_ts.tv_nsec = 0;    

    pthread_set_mode_np(0, PTHREAD_WARNSW);

    printf("start\n");

    while (1)
    {
        count++;
        clock_nanosleep(CLOCK_REALTIME, 0, &dt_ts, NULL);
        printf("%d", count);
        printf("\n");
    }
    
    return NULL;
}

int main(void)
{
    pthread_attr_t attr;
    pthread_t rt_thread;
    struct sched_param sparam;
  
    mlockall(MCL_CURRENT | MCL_FUTURE);

    sparam.sched_priority = 16;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
    pthread_attr_setschedparam(&attr, &sparam);
    pthread_create(&rt_thread, &attr, &rt_loop, NULL);
    pthread_attr_destroy(&attr);

    pthread_join(rt_thread, NULL);

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

Reply via email to