Thread safety in the ARM C++ library

The following points summarize thread safety in the C++ library:

Show/hideRogue Wave Standard C++ library

The Rogue Wave Standard C++ library is a part of the ARM C++ library. What applies to the ARM C++ library applies to the Rogue Wave Standard C++ library too. In the Rogue Wave Standard C++ library, specifically:

  • all containers and all functions are reentrant, making no use of internal, modifiable static data

    • except for the std::random_shuffle function, which uses static data to record the random number

  • The iostream and locale classes are not thread safe.

You must protect shared objects while using the iostream and locale classes, and the std::random_shuffle function. To do this, you might use mutex functions, or co-operative threading. As an example, in a typical case of a pre-emptive multitasking environment, one that uses mutex functions with containers, this means that:

  • reader threads can safely share a container if no thread writes to it during the reads

  • while a thread writes to a shared container, you must apply locking around the use of the container

  • writer threads can write to different containers safely

  • you must apply locking around the use of random_shuffle

  • multiple threads cannot use iostream and locale classes safely unless you apply locking around the use of their objects.

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0475H