This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ constructor calling futex_wake then _spin_lock


>> I am experimenting with RAII for locks and uses a stack object to initialize a lock. While this method is very practical, using it on the critical path of my application shows extremely strange behaviors.
>> 
>> It looks like somehow kernel spin locks, through futex, are involved during the construction and destruction of my RAII locker. Is this an expected behavior? It's rather counter intuitive and extremely expensive (70% CPU time with multiple threads).
> 
> 
> Pthreads mutexes use kernel facilities for parking threads which cannot acquire a mutex, so this behavior is expected for contended mutexes. Avoid contention and execution will stay in user space.

Right...

> I don't quite see how this is related to libstdc++, though.

The locking seemed to stem from a collateral effect linked to the runtime itself (construction/destruction). After some investigation, it turns out the locking come from the exception handling mechanism, in dl_iterate_phdr, from _Unwind_Find_FDE, as some behavior of my code would often trigger a throw after an RAII lock. Changing the code to avoid throw fixed the issue.

If I am not mistaken, this problem has a runtime origin, ergo this mailing list. If this is the wrong audience, please accept my apologies.

Xavier


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]