https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77744
Bug ID: 77744
Summary: Data race on std::regex_iterator using openmp
Product: gcc
Version: 6.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgomp
Assignee: unassigned at gcc dot gnu.org
Reporter: morandidodo at gmail dot com
CC: jakub at gcc dot gnu.org
Target Milestone: ---
Created attachment 39687
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39687&action=edit
Output of the test program with thread sanitizer
Here this simple piece of code:
#include <regex>
#include <string>
int main()
{
const std::string test = "this is a test";
const std::regex reTest("[ths]");
auto f = [&test, &reTest]()
{
std::sregex_iterator iter(std::begin(test), std::end(test), reTest);
};
#pragma omp parallel for
for(unsigned i = 0; i < 10; ++i)
f();
}
If run with thread sanitizer, it will warn about some data races (see
attachment).
A similar example using std::threads...
#include <regex>
#include <string>
#include <thread>
int main()
{
const std::string test = "this is a test";
const std::regex reTest("[ths]");
std::vector<std::thread> threads;
auto f = [&test, &reTest]()
{
std::sregex_iterator iter(std::begin(test), std::end(test), reTest);
};
for(unsigned i = 0; i < 10; ++i)
threads.emplace_back(f);
for(std::thread& curThread : threads)
curThread.join();
}
...will not trigger any data race.