Page MenuHome

Patch to solve crash in audaspace
Closed, ResolvedPublicPATCH

Description

This patch fixes bug #31097 [1]. The bug occurred with short time sounds.

The root cause of the problem was that AUD_Reference is not thread safe, not even for reference counting, which caused race conditions between AUD_OpenAL_Device::updateStreams and KX_SoundActuator::Update.

This patch apply a global mutex to AUD_Reference, which is bad, since it increases contention in SMP machines. My original solution was to implement AUD_Reference in terms of boost::shared_ptr, which provides thread safe (and even lock free) implementation of reference counting, but because AUD_Reference allows you to associate a raw pointer to two distinct objects, preserving reference counting sanity, it was not possible to use boost::shared_ptr.

Also, I had to use a recursive mutex to avoid dead locks, which is slower than a ordinary mutex. The mutex implementation which I chose was boost::recursive_mutex, because boost is already used in Blender and because it is portable.

A better solution would be associate a mutex to each pointer being wrapped (maybe expanding the std::map inside AUD_ReferenceHandler), but things are not so simple because boost::recursive_mutex is a noncopyable type, so we would probably have to use a shared_ptr to store it inside a map, and since AUD_Reference is restricted to audaspace module, I don't know if over complicating the code would bring real life benefits.

Thanks,
Wander Lairson Costa

[1] http://projects.blender.org/tracker/?func=detail&atid=498&aid=31097&group_id=9

Event Timeline

Joerg Mueller (nexyon) changed the task status from Unknown Status to Resolved.Apr 28 2012, 10:26 PM