6 years, 1 month ago.

"Not enough stdlib mutexes" Error Message

I have just started to develop some software using the RTOS. Have a simple program running 3 threads (plus main). Main's function is to interface to the pc via the usb serial port. The other threads just blink a light, wait a bit, and blink again. Later they will each be doing serial communication, but this is just a shell at this point.

Everything is running normally 99.9% of the time and then a message pops up on my terminal screen "Not enough stdlib mutexes" and the LPC1768 starts flashing lights. Reset cleared it and it did not occur again (yet).

Any ideas on what the underlying cause of this error might be? It happened once and now I can't seem to reproduce it.

Thanks!

1 Answer

6 years, 1 month ago.

There is a limitted number of Stream objects which can be made when using RTOS. Serial is for example one of those, but also for example many LCD display libraries use it.

But it should never happen with just a single Serial. Is it possible that you have a memory leak? Where it for example keeps making new Serial objects?

I guess it's possible that there is a memory leak, but I'm not sure how to check for that. Is there a function that returns available memory, that I could use to monitor for a leak? Is there a limit on stack space that could get used up quickly? I've got about 16K of available memory, according to the compiler. The program is pretty basic at this point, basically just receives a few bytes via serial, and sends a few bytes back.

posted by Chuck Davis 24 Jan 2015

Only way to really create a memory leak is to use 'new' (or 'malloc') to create objects in a loop, without deleting them afterwards.

Although in this specific situation I would try to make sure you don't create Serial in any way in a loop (in general it is from a performance pov bad to do it also).

posted by Erik - 24 Jan 2015