PiRSquared17 / re2

Automatically exported from code.google.com/p/re2
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

runtime failure: Windows: GLOBAL_MUTEX is not linker-initializer #85

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

Here's the steps:

1. Compile re2 to a lib
2. Link against it
3. Create an instance of a static regexp (either as a global variable or a 
static member of some class initialized).
4. In certain circumstances you will see an unhandled exception in InitEmpty. 
GLOBAL_MUTEX_LOCK -> void Mutex::Lock()         { EnterCriticalSection(&mutex_);

Version: 2013-06-22
Platform: MSVS 2008 (compiled with NOMINMAX;NOGDI;COMPILER_MSVC) + Win7 

I.e. it looks like the empty_mutex was not initialzed when regexp is created 
(i.e. init hasn't been executed yet "GLOBAL_MUTEX(empty_mutex);"), which is a 
known thing as the order of static variable initialization is not defined 
(well, someone wasn't keen on the idea in the first place: "// Provide safe way 
to declare and use global, linker-initialized mutex. Sigh." in mutex.h).

For now I'm just using "NO_THREADS" preprocessor definition but it would be 
nice to have an _EXPLICIT_ function "init_re" or something of that kind that I 
could call in the order I need.

Thanks.

Original issue reported on code.google.com by DenisKra...@gmail.com on 2 Jul 2013 at 2:15

GoogleCodeExporter commented 9 years ago
The goal of the GLOBAL_MUTEX macro is to declare a global mutex that has the 
correct memory image (typically all zeros) set during compilation and linking, 
so that there is no run-time initialization. It appears that that is not true 
for what we're using on Windows. The fix is to find a way to do that.

Maybe we have to do something like
http://stackoverflow.com/questions/3555859/is-it-possible-to-do-static-initializ
ation-of-mutexes-in-windows
on Windows.

Original comment by rsc@golang.org on 10 Jan 2014 at 3:12

GoogleCodeExporter commented 9 years ago

Original comment by rsc@golang.org on 10 Jan 2014 at 3:12

GoogleCodeExporter commented 9 years ago
RE2 has moved to GitHub. I have not moved the issues over. If this issue is 
still important to you, please file a new one at 
https://github.com/google/re2/issues. Thank you.

Original comment by rsc@golang.org on 11 Dec 2014 at 4:45