Comments (1)
It is not related to the deadlock but after attaching something to the Listener one cannot use it anymore outside of the listener to send/receive data until it is detached. The reason for this is that neither of the endpoint instances are thread safe.
Regarding the deadlock. It looks like there is indeed a case were a deadlock can happen due to the check whether the event is already attached.
legend: ----> function calls from main thread
~~~~> function calls from listener thread
main thread Listener m_events[0..3] eventAddMutex
| | |||| |
| | |||| |
| |\ listener thread |||| |
| | \ |||| |
| | \ |||| |
| | | executeCallback(id=2) |||| |
| | ▬~~~~~~~~~~~~~~~~~~~~~~~~~>X| |
| | ▬<~~~~~~~~~~~~~~~~~~~~~~~~~X| |
| | ▬ ||X| |
| attach | ▬ ||X| |
▬-------------->| lock ||X| |
▬ ▬---------------------------------------------->X
▬ ▬<----------------------------------------------X
▬ ▬ isEqualTo(id=0) ||X| X
▬ ▬-------------------------->X|X| X
▬ ▬<--------------------------X|X| X
▬ ▬ isEqualTo(id=1) ||X| X
▬ ▬--------------------------->XX| X
▬ ▬<---------------------------XX| X
▬ ▬ isEqualTo(id=2) ||X| X
▬ ▬---------------------------->X|⚡already locked by listener thread
▬ ▬ ▬ ||X| X
▬ ▬ ▬ attach ||X| X
▬ ▬ ▬~~~~~~~~~~ ||X| X
▬ ▬ ▬ ~ ||X| X
▬ ▬ ▬▬<~~~~~~~~ ||X| X
▬ ▬ ▬▬ lock ||X| X
▬ ▬ ▬▬~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>X⚡already locked by main thread
▬ ▬ ▬▬ ||X| X
▬ ▬ ▬▬ ||X| X
I'm not that familiar with the Listener
but maybe a custom event could be added which then adds the clients from within the listener thread.
Unfortunately we cannot use try_lock
in this case since it can spuriously fail and it is undefined behavior to call it from a thread that holds the mutex. To fix this we would need to implement a lock-free check for the isEqualTo
functionality.
Edit:
Maybe this can be solved by std::shared_mutex
with a std::shared_lock
in isEqualTo
. The executeCallback
method requires an additional mutex and in init
and reset
both mutex need to be owned exclusively.
I'm not sure if there is another issue though. When an event is detached from within the listener thread, it might lead to another deadlock or a race but I have to think more about it. The problem is that the slot is marked as free while the callback is still running and if an event is attached in the callback right after the detach it might get the same slot.
@elfenpiff @budrus @MatthiasKillat you are more familiar with the listener. What do you think about my proposal?
from iceoryx.
Related Issues (20)
- Add an 'iox1' prefix to all resources created by 'iceoryx_posh' and 'RouDi' HOT 1
- Test Fixtures for RouDi HOT 2
- Gateway: Support Client/Server in GatewayGeneric HOT 4
- Race condition in 'PoshRuntime' during shutdown
- mutex owner died -> POPO__CHUNK_LOCKING_ERROR HOT 17
- RouDi-GTest Multithread Integration Test HOT 1
- Wrong memory order in MpmcLoFFLi fence synchronization
- Iceoryx support fast-dds HOT 1
- 'NamedPipe' should be more robust
- ChunkHeader should expose the size of the entire user payload section, including padding HOT 6
- Explore cmake object libs for modules iceoryx hoofs HOT 1
- Problems with multiple "persistent" publishers on the same topic at subscriber startup HOT 3
- ssize_t: redefinition; different basic types HOT 3
- Generated files cause recompilation even without any changes HOT 2
- IPC channel still there, doing an unlink of instanceName HOT 5
- Declared but undefined copy assignment operator for iox::expected HOT 1
- Add aliases that conform with other STL container types HOT 2
- Linear search when releasing a sample scales very poorly HOT 38
- Can't directly assign `const` underlying value to `iox::optional` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iceoryx.