Demonstration of the use of sprintf() causing a run time problem with RTOS.

Dependencies:   mbed

main.cpp

Committer:
tylerjw
Date:
2012-02-16
Revision:
0:7fecc17e2765

File content as of revision 0:7fecc17e2765:

#include "mbed.h"
#include "rtos.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);

char* teststring = "";
int testint = 65;

// uncomment only one of the sprintf functions at a time to see it fail at that point

void led2_thread(void const *argument) {
    while (true) {
        led2 = !led2;
        //sprintf(teststring, "This is a test: %d", testint);
        Thread::wait(1000);
    }
}

int main() {
    Thread thread(led2_thread);
    //sprintf(teststring, "This is a test: %d", testint);
    
    while (true) {
        led1 = !led1;
        sprintf(teststring, "This is a test: %d", testint);
        Thread::wait(500);
    }
}