julius-speech / julius

Open-Source Large Vocabulary Continuous Speech Recognition Engine
BSD 3-Clause "New" or "Revised" License
1.84k stars 300 forks source link

Suggestions to avoid communication deadlocks #181

Open ryancaicse opened 2 years ago

ryancaicse commented 2 years ago

Hi, developers, it seems there are multiple sites using wait conditions in the wrong ways, which could lead to deadlocks.

Normally, the wait is checked via a condition to ensure the notify that hasn't been executed. For example, https://github.com/julius-speech/julius/blob/4182bf024872cf4ff4388475359d74695dd5ee16/msvc/Library_PortAudio/src/src/hostapi/jack/pa_jack.c#L1025-L1032

https://github.com/julius-speech/julius/blob/4182bf024872cf4ff4388475359d74695dd5ee16/msvc/Library_PortAudio/src/src/hostapi/jack/pa_jack.c#L670-L673

However, there are multiple sites, which miss checking such conditions. The deadlock could happen when the signal reaches in advance so that the waiting site could lead to a wait forever with no signal notifying anymore.

https://github.com/julius-speech/julius/blob/4182bf024872cf4ff4388475359d74695dd5ee16/msvc/Library_PortAudio/src/src/hostapi/jack/pa_jack.c#L1625-L1641

https://github.com/julius-speech/julius/blob/4182bf024872cf4ff4388475359d74695dd5ee16/msvc/Library_PortAudio/src/src/hostapi/jack/pa_jack.c#L1660-L1668

https://github.com/julius-speech/julius/blob/4182bf024872cf4ff4388475359d74695dd5ee16/libsent/src/adin/pa/hostapi/jack/pa_jack.c#L1621-L1637

https://github.com/julius-speech/julius/blob/4182bf024872cf4ff4388475359d74695dd5ee16/libsent/src/adin/pa/hostapi/jack/pa_jack.c#L1656-L1664

ryancaicse commented 2 years ago

Or, I just missed some things important? Looking forward to furthering discussion.