Even the STL and IOS and Strings libraries are not thread safe.
One way to overcome this problem is to use semaphore locking around every call to any of these libraries, but that is inefficient, and too much locking can cause deadlocks.
There were other motivations for making a new string class, and a hash-map class:
The new string class is called "text".
The hash-map in The Karoo Project uses an array of buckets, each corresponding to one possible hashed key, and each containing a variable length array of entries. The hashing algorithm is built in to the text class. It uses the sdbm algorithm, which creates an evenly distributed hash.
When a new element is added to the hashmap, first the load-factor is checked. If the hash-map is too loaded, then it needs to be re-hashed. In this case, a write-lock is obtained for the bucket array. Then the buckets and their chained elements are iterated over and a new (larger) bucket array is created. Then the bucket array's write-lock is released. Once the (infrequent) rehashing is concluded, then the element's hash is calculated from the key, and a read-lock is obtained for the buckets. Then the bucket is located, and that backet is locked for write. The element is inserted in the chain, and the locks are released.
So you can see how that only part of the hash-map is locked at any one time, and the whole hash-map is only locked out for read when it's being (relatively infrequently) re-hashed. If the hashmap is read more than it is written, then the read-locks will allow many threads to read at once. Its only when something is being inserted or erased, that one particular bucket will be locked for write, but at the same time, all the other buckets can be read from... or written to for that matter.
However, having said all this, the map and multimap in the STL are excellent, though not thread-safe. There is no simple way to make them partially locked (as with a hashmap). So the best way to use them (if you need a red/black tree, as I did, in the queue class), is to use a semaphore lock around every call to it.
The hashmap's iterator does not return elements in order. The order is not quite random, but may as well be for all intents and purposes. So if you need an ordered iterator, you need a bin-tree (or even better, a red/black tree) such as the map and multimap templates in STL.
1.5.8