Exception when using C++ standard library

This is the function I'm testing with:

{
  std::string msg;

  uint32_t i=0;
  for (i=0; i<0xffffffff; i++) {
    try {
      msg.append(" ");
    }
    catch (std::exception& e) {
      break;
    }
  }
}

This function appends a space to msg until there is no room left and a "bad allocation" exception is caught.  This is working as I expect it.  Looping on this function will go forever.

With a second thread looping on this same function, the S5 will eventually take a debug event exception.

It seems to have heap problems when multiple threads are accessing it.  Am I doing something wrong?  How do I prevent this?

I'm using SSP 1.5.1 and  IAR ANSI C/C++ Compiler V8.23.1.17106.