Fix RCU race condition (see source for details)

This commit is contained in:
Robin Gareus 2024-04-12 00:26:25 +02:00
parent 96e83f4101
commit 44610c7877
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
1 changed files with 15 additions and 1 deletions

View File

@ -220,13 +220,27 @@ public:
boost::detail::yield (i);
}
#if 0 // TODO find a good solition here...
/* if we are not the only user, put the old value into dead_wood.
* if we are the only user, then it is safe to drop it here.
*/
if (!_current_write_old->unique ()) {
_dead_wood.push_back (*_current_write_old);
_dead_wood.push_back (*_current_write_old);
}
#else
/* above ->unique() condition is subject to a race condition.
*
* Particulalry with JACK2 graph-order callbacks arriving
* concurrently to processing, which can lead to heap-use-after-free
* of the RouteList.
*
* std::shared_ptr<T>::use_count documetation reads:
* > In multithreaded environment, the value returned by use_count is approximate
* > (typical implementations use a memory_order_relaxed load).
*/
_dead_wood.push_back (*_current_write_old);
#endif
/* now delete it - if we are the only user, this deletes the
* underlying object. If other users existed, then there will