-
Notifications
You must be signed in to change notification settings - Fork 418
Deadlock when accessing smart lock twice within the same expression #2448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just to be clear - we aren't blocked in any way by this since it was trivial to split up the initialization of that member such that the But I felt that this pitfall warranted calling attention to, if not finding a clever solution for. |
It seems like
should be
|
@gpalmer-latai it's already late and I have to think this through but I think your proposal would unlock the mutex while one is still operation on the underlying type. For situation where the wrapped type has to be used multiple times in the same expression, one can use the scope guard
But this does not work in your situation. A workaround might be to use an immediately invoked lambda , segment_manager_(
[&] { return m_ipcChannelInterface->getSegmentManagerAddressOffset(); } (), ...)
|
Hm. You are right. What the ideal behavior would be is that once |
Well, maybe it is possible with C++26 reflection by essentially generating a wrapper class that mirrors operations on the underlying class with a lock around them. |
I think a recursive as underlying mutex for the smart lock solves the problem, see: https://en.cppreference.com/w/cpp/thread/recursive_mutex @gpalmer-latai I think the usage of this is itself a bug:
Let's assume it would work like intended (without the deadlock).
|
@elfenpiff right, a recursive mutex would solve that problem @gpalmer-latai you can specify the mutex type with the second template parameter |
@gpalmer-latai can this be closed? The smart-lock works as intended and when a immediately invoked lambda or a recursive mutex is used, the problem does not appear. |
Sure. |
Required information
For the reasons described in #2128 and #2092 we have implemented our own derived version of the PoshRuntime where the segment manager is exposed, like so:
Whilst updating our fork of Iceoryx to a more recent HEAD, we encountered the problem where suddenly a deadlock is occurring at this line of code.
It turns out to be caused by #2191 which added a
smart_lock
aroundm_ipcChannelInterface
.operator->
onsmart_lock
relies on the RAII behavior of a prvalueProxy
whose lifetime, unfortunately, is bound to that of this statement. This means in effect that twoProxy
objects will be created, both of which calllock()
on the same mutex in their construct, and neither of which callunlock()
until the statement is complete - which does not happen because the secondProxy
blocks in thelock()
call.Operating system:
Ubuntu 24
Compiler version:
Clang 14
Eclipse iceoryx version:
main
Observed result or behaviour:
A deadlock when making two calls to a
smart_lock
object in the same statementExpected result or behaviour:
The smart lock is unlocked once the operation under
->
is completed, thus not causing a deadlock when used twice within the same statementConditions where it occurred / Performed steps:
There are a lot of ways this could be triggered, but in particular you can create a class like
Additional helpful information
The text was updated successfully, but these errors were encountered: