You can make sure that the library in question is used from only one thread at a time. If it contains instanceable classes, one possibility is to keep them in threaded local storage .
Or you can create a thread-safe wrapper around it.
These approaches can also be combined, for example. you can wrap the library in a class (in this case it will be Facade ), which in itself is not thread safe, but whose instances you access from one thread at a time.
Update: as pointed out by @Wim, if the library manages global state, you must have a thread-safe shell to ensure that changes become visible between threads.
source share