8 years, 9 months ago.

Using push to std:queue freezes program

Hi,

I am implementing some kind of message parser, so I wanted to add FIFO functionality, so I have decided to use queue from std, but whe I try to call queue.push(T) than program freezes and cant send anything through serial, I am having same problem with vector.push_back

include the mbed library with this snippet

#include "mbed.h"
#include <vector>

Serial pc(SERIAL_TX, SERIAL_RX);
MessageParser mp(&pc);

void addChar() {

    unsigned char c = pc.getc();
    pc.printf("C");
    std::vector<unsigned char> f;
    pc.printf("M");
    f.push_back(c); // freezes here
    pc.printf("E");
}

int main() {

    pc.attach(&addChar);
    while(true) {
    	wait(0.5);
}

You are not using RTOS or have it even on your program? Which target are you using?

posted by Erik - 07 Mar 2016

I don't use RTOS, is it needed? I am using NUCLEOF411re

posted by Son Hai Nguyen 07 Mar 2016
Be the first to answer this question.