Reading the documentation is recommended:
the
scoped_session()function is provided which produces a thread-managed registry ofSessionobjects. It is commonly used in web applications so that a single global variable can be used to safely represent transactional sessions with sets of objects, localized to a single thread.
In short, use scoped_session() for thread safety.