[Stlport-devel] Uninitialized _STLP_STATIC_MUTEX in _Node_Alloc_Lock
Brought to you by:
complement
From: Peter H. <p.h...@sc...> - 2008-05-13 08:44:31
|
Hi, I have the following code which I compile in a shared object: #include <map> class MyRegistry { public: static MyRegistry& get() { static MyRegistry instance; return instance; } void registerEntry(int a, int b) { mMap[a] = b; } private: std::map<int,int> mMap; }; class MyEntry { public: MyEntry(int a, int b) : _a(a), _b(b) { MyRegistry::get().registerEntry(a,b); } private: int _a; int _b; }; MyEntry first(1,2); I link this shared object to a trivial main programm: int main( int argc, char* argv[]) { } But if I try to run this with STLport 5.1.5 (which I compiled myself from source with gcc-4.1.1) using _STLP_DEBUG on openSUSE 10.2, x86-64, my programm busy-waits in _Node_Alloc_Lock::_Node_Alloc_Lock() in pthread_spin_lock. Debugging into this I found that the static member _Node_Alloc_Lock::_S_lock is initialized with pthread_spin_init AFTER the first call to pthread_spin_lock (you obviously have to force pthread_spin_lock to return anyway in order to see that). The static initialization of "MyEntry" happens before the static initialization of the lock. It works as expected if I implement _Node_Alloc_Lock as follows: class _Node_Alloc_Lock { public: _Node_Alloc_Lock() { # if defined (_STLP_SGI_THREADS) if (__us_rsthread_malloc) # endif getLock()._M_acquire_lock(); } ~_Node_Alloc_Lock() { # if defined (_STLP_SGI_THREADS) if (__us_rsthread_malloc) # endif getLock()._M_release_lock(); } static _STLP_STATIC_MUTEX& getLock() { static _STLP_STATIC_MUTEX instance _STLP_MUTEX_INITIALIZER; return instance; } }; Regards, Peter Hrenka -- Vorstand/Board of Management: Dr. Bernd Finkbeiner, Dr. Florian Geyer, Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech Vorsitzender des Aufsichtsrats/ Chairman of the Supervisory Board: Prof. Dr. Hanns Ruder Sitz/Registered Office: Tuebingen Registergericht/Registration Court: Stuttgart Registernummer/Commercial Register No.: HRB 382196 |