Queue dosent remove items in the list after try_get

I have a setup of
1-thread to reply,
2-Thread to receive,
3-main thread that treat the message.
2 queue (queueRX, queueTX)
Now, up to 64 (which is the size of the queue) the communications works. After getting more than 64 msg, the queue becomes full and the communications constantly fails.
I am sure that I take out the messages in the main thread, using (try_get) but stills the queueRX is full.
It seems that the pointers to std::string remains in the queueRX even if i take them using try_get and I treat the messages I have.
I even delete the memory and put NULL to the variable just to make it sure that we don’t have anything left. But still the queue is full.
This must be a bug in the Mbed OS.

in the main : I have

	if (queueRx.try_get(&cmd)) {
			std::string command(*cmd);
			delete cmd;
			cmd = NULL;

in the thread that fails I have this part

					std::cout << "msg was =" << rxBuf << std::endl;
					std::string* str = new std::string(rxBuf);
					while (queueRx.try_put(str) != true) {
						//This might be bad, it should wait
						// to the time it can put the data to the queue
						if (queueRx.full()) {
                            printf("queueRX size%i\n",queueRx.count());
							printf("I am full\n");

I get in the console after 64 messages (64 and I am full)
Any suggestion please?


try to get size of queue via count method before and after try_get method. When the queue is not cleaned after try_get, then the size must be same or your read method have to return still one same msg over and over.

Maybe more context about the communication could be handy. Because according to this it seems your read method is too much slow and your write method is too fast.

BR, Jan

I checked that. It seems that Main thread which starts the other threads are not running. I have sleep in both other threads, but still main is not working after first run.
If it is crashing, it should crash both other threads.
But it seems that it doesn’t run at all.

	while (1) {
		if (queueRx.full()) {
			printf("I have data - full\n");
            printf("queueRx was =%i\n",queueRx.count());
            if (queueRx.try_get(&cmd)) {
                printf("queueRx after was =%i\n",queueRx.count());
                std::string command(*cmd);
                delete cmd;
                cmd = NULL;
                val = convertToEnum(command);
                std::cout << "Value is = " << std::to_string(val) << " cmd=" << command << "\n";
                switch (val) {
                    case TEST_24V: {
                    case TEST_12V: {
                    case TEST_END: {
                if (DUTtest->partialResults.size()>0){
                    results = DUTtest->partialResults;
                    if (results.size() > 0) {
                        //We have results to send.
                        std::string* tempStr = new std::string(results);

	//Just in case, we go out from while(1)
	clientSocket = NULL;
	printf("Close-main thread\n");


HI again,
I know what was happening now.
In the main thread, I test different peripherals, some digital and 5 UART:s
This function which should send a message to the UART was not getting the job done as there is no devices connected yet to the UART:s.

#define SLEEP_FOR(x)  rtos::ThisThread::sleep_for(chrono::milliseconds(x));
bool func(){
testTarget->write(testName.c_str(), testName.size());
	SLEEP_FOR(30);   //Sleep for
	char buf[512];
	testTarget->read(&buf, 511);
	std::string result = buf;
	return false;

But it was never getting out of this function and was blocking main thread to run.
by putting return false in the beginning of the function, the failure is not happening.
here is the link for the blocking parameter


UART Blocking /unblocking should be used I guess.

BR /Mariwan