[En-Nut-Discussion] Curious behaviour with strcat(tdp->td_name, "\n")

Marcel Bariou nut.dev at brasnah.com
Fri Jul 22 19:21:51 CEST 2005


The following is a modified version  of  Harald threads example. When I add the last line :

puts(strcat(tdp->td_name,"\n"));

I find out a quick degradation of the output, have somebody an idea about ?

Thanks

Marcel 

============================================
/*!
 * \example threads/threads.c
 *
 * This sample demonstrates Nut/OS multithreading.
 *
 * Each thread is started with 192 bytes of stack. This is very
 * low and doesn't provide much space for local variables.
 */

#include <stdio.h>
#include <string.h>
#include <io.h>

#include <cfg/arch.h>
/* Only devDebug1 supported with AT91 */
#ifdef MCU_AT91R40008
#include <dev/debug.h>
#define DEV_UART devDebug1
#define DEV_UART_NAME "uart1"
#elif defined(MCU_GBA)
/* Only devDebug0 with name "con" supported with GBA */
#include <dev/debug.h>
#define DEV_UART devDebug0
#define DEV_UART_NAME "con"
#else
#include <dev/usartavr.h>
#define DEV_UART devUsartAvr0
#define DEV_UART_NAME "uart0"
#endif
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/heap.h>
/*
 * High priority thread.
 */
THREAD(Thread1, arg)
{
    /*
     * Endless loop in high priority thread.
     */
    NutThreadSetPriority(16);
    for (;;) {
        printf("H => Prioritaire \n");
        NutSleep(1230);
    }
}

/*
 * Low priority thread.
 */
THREAD(Thread2, arg)
{
    /*
     * Endless loop in low priority thread.
     */
    NutThreadSetPriority(128);
    for (;;) {
        putchar('L');putchar('\n');
        NutSleep(3125);
    }
}

//static char buff[128];

/*
 * Main application thread. 
 */
int main(void)
{
    u_long baud = 115200;
 NUTTHREADINFO *tdp;
    NUTTIMERINFO *tnp;
 
   /*
     * Register the UART device, open it, assign stdout to it and set 
     * the baudrate.
     */
    NutRegisterDevice(&DEV_UART, 0, 0);
    freopen(DEV_UART_NAME, "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
 fflush(stdout);

    puts("\nThread");
 
    /*
     * Start two additional threads. All threads are started with 
     * priority 64.
     */
    NutThreadCreate("t1", Thread1, 0, 192);
    NutThreadCreate("t2", Thread2, 0, 192);
 

    for (;;) {
        putchar('O');
          putchar('\n');
          NutSleep(6250);
  
            for (tdp = nutThreadList; tdp; tdp = tdp->td_next) {
            printf("Available Ram %u bytes\n", NutHeapAvailable());
            puts(strcat(tdp->td_name,"\n"));    
            }
        
    }
}



More information about the En-Nut-Discussion mailing list