cxa_guards cause deadlock in static initialization.

Number:rdar://11217150 Date Originated:10-Apr-2012
Status:Open Resolved:
Product:clang++/g++-llvm Product Version:3.1 tags/Apple/clang-318.0.58
Classification:deadlock/crash Reproducible:always
10-Apr-2012 10:57 AM Zeno Albisser:
The cxa_guards used to protect static initialization cause a deadlock, when a static initialization depends on another one. It seems that the cxa_guards are implemented using a single mutex for the whole application. This seems rather harmful. Instead there should be a mutex per initialization.
This bug especially affects the Qt open source project. Because static initialization is used in several places there.

Steps to Reproduce:
- Compile the attached code using g++ or clang++:
$ g++ cxabug.cpp
- Run the created binary:
$ ./a.out

Expected Results (when compiled on linux): 
Creating FirstStatic... waiting for the semaphore.
SecondStatic created... unlocking the semaphore.
This is local static #2
This is local static #1

Actual Results (when compiled on mac):
Creating FirstStatic... waiting for the semaphore.

I think this problem persists with all available compiler versions on mac os x.

10-Apr-2012 10:58 AM Zeno Albisser:
'cxabug.cpp' and 'deadlock.log' were successfully uploaded



By zeno.albisser at May 15, 2012, 10:06 a.m. (reply...)


By zeno.albisser at May 15, 2012, 10:04 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!