Working in a Multithreaded Environment
Increasingly, developers use multithreading techniques to improve the throughput and responsiveness of their applications. In exchange for these performance gains, developers must assume responsibility for ensuring the integrity of shared resources, such as shared data. To do this, it is important to know the multithread capabilities of underlying libraries, and to use appropriate concurrency controls.
With care, you can use the classes of the Internationalization Module in multithreaded applications. For example, the conversion context stacks maintained by
RWUToUnicodeConversionContext,
RWUFromUnicodeConversionContext, and
RWUConversionContext exist on a per-thread basis. Creating a conversion context in one thread pushes the context on that thread's context stack, and does not affect the context stacks of other threads.
The classes of the Internationalization Module, however, are not re-entrant. They do not use concurrency controls, such as mutexes, to protect their internal data. This minimizes the overhead of using an object within a single thread, but also means that an unprotected object cannot be shared safely between threads. Instead, you can:
Use the classes of the Synchronization Package within the Threads Module of SourcePro Core to serialize access to Internationalization Module objects.
Create copies of Internationalization Module objects, and use one copy per thread. This option is not as expensive as it sounds. Most Internationalization Module objects are fairly lightweight, containing a small amount of state data and references to shared, read-only data. For example, each
RWUCollator object contains just a handful of attribute values. The bulk of the collation data used by an
RWUCollator is shared in a read-only fashion by all
RWUCollator objects.