3 Aug
2011
3 Aug
'11
3:31 a.m.
Thanks Daniel and Oliver, I appreciate it. The static expression is exactly what the problem was. Here's a discussion in case anyone else ever comes across the same problem with the boost.regex example code that uses a static regex: http://stackoverflow.com/questions/4590626/c-static-variables-in-multithreaded-program >From: >"Oliver Seiler">To: >boost-users@lists.boost.org >I've generally found that using function-level static with multiple >threads is a Bad Idea (including with Boost.Threads) as the object >won't get initialized until the function is run for the "first" time, >but this initialization isn't generally thread-safe. Consider moving >the static regex out of the function (e.g., into an anonymous >namespace) so that it is initialized at global static initialization >time. >here few suggestions: - What if you put the regex automatic instead of static ? often objects of classes a thread safe when different object are use (they do not share static data), but the same object cannot be used within two thread without some ways to serialize access which must be done by the user of the object. - if you keep the regex static within the function, at least make the construction thread safe. Daniel Anderson