QuantLib default session handling is thread safe only if you allocate all sessions beforehand, otherwise adding/removing a session id changes the map object potentially corrupting other thread iterators.
This patch uses boost::thread_specific_ptr to have a per-thread session id. Since the variable used is thread-private and inherently linked to the thread, no sessionId() method is needed.
The patch is enabled by defining QL_ENABLE_SESSIONS_TSS in config.hpp
Without the define QuantLib uses the old code.