Tool/software: Code Composer Studio
I'll explain the setup.
- Inside interrupts, instead of actually printing through UART, I queue up print "objects" (can be multiple strings, numbers, etc). This involves allocating space on the heap, as the number of objects varies.
- Inside the main thread, I empty that queue. All of the code works quite well (no mangled text, no issues with text being printed out of order, etc).
What is happening, is very rarely, and only when I'm printing very quickly (think 100+ times per sec), the program will lock up on the delete[] that frees the list of objects that were just printed. I only know this because I've added timestamps (IpcRegs.IPCCOUNTERL) throughout the main loop in an effort to debug it. The program will just never return from delete[].
Thinking this could be an issue with calling new/delete from different threads, I've added blocks of disable_interrupts/restore_interrupts around each new[] or delete[] that are called frequently (as opposed to one-offs that are called at program startup). This seems to be working, as I've let it run for an hour (@100 calls per second), with it freezing.
However, I'm curious if there is a better way to do this. It just feels a little off to be disabling and restoring interrupts so frequently, even though I've verified that no interrupts are being lost (the new/delete time is much much less than the smallest interrupt interval of 1 ms).