thread_safety.qbk 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. [/
  2. Copyright 2006-2007 John Maddock.
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ]
  7. [section:thread_safety Thread Safety]
  8. The Boost.Regex library is thread safe when Boost is: you can verify that
  9. Boost is in thread safe mode by checking to see if `BOOST_HAS_THREADS` is
  10. defined: this macro is set automatically by the config system when
  11. threading support is turned on in your compiler.
  12. Class [basic_regex] and its typedefs regex and wregex are thread safe,
  13. in that compiled regular expressions can safely be shared between threads.
  14. The matching algorithms [regex_match], [regex_search], and [regex_replace]
  15. are all re-entrant and thread safe. Class [match_results] is now thread safe,
  16. in that the results of a match can be safely copied from one thread to
  17. another (for example one thread may find matches and push [match_results]
  18. instances onto a queue, while another thread pops them off the other end),
  19. otherwise use a separate instance of [match_results] per thread.
  20. The [link boost_regex.ref.posix POSIX API functions] are all re-entrant and thread safe, regular
  21. expressions compiled with regcomp can also be shared between threads.
  22. The [link boost_regex.ref.deprecated.old_regex class RegEx] is
  23. only thread safe if each thread gets its own
  24. RegEx instance (apartment threading) - this is a consequence of
  25. RegEx handling both compiling and matching regular expressions.
  26. Finally note that changing the global locale invalidates all compiled
  27. regular expressions, therefore calling `set_locale` from one thread
  28. while another uses regular expressions will produce unpredictable results.
  29. There is also a requirement that there is only one thread executing prior
  30. to the start of main().
  31. [endsect]