Page MenuHome

Implement AUD_Reference in terms of boost::shared_ptr to ensure basic thread safety
Closed, ResolvedPublicPATCH

Description

This patch implements AUD_Reference in terms of boost::shared_ptr.

The old implementation of AUD_Reference suffers from race conditions, because it does not provide thread safe reference counting. Previous attempts to fix this using mutexes [1,2] were not sucessfull, because when the race condition was fixed, deadlocks raised.

shared_ptr provides thread safe (and even lock free in popular platforms) reference counting, and ensures basic thread safety (accessing different objects from different threads is safe), what is enough to fix the race conditions in the audaspace module.

There is one important restriction, however. The following code:

class A{};

A *pa = new A;
AUD_Reference<A> r1(pa);
AUD_Reference<A> r2(pa);

used to be valid, because the reference counting was stored in a global table. Now with shared_ptr, this causes a double delete, so this should be avoided. During tests I detected one situation of this in OpenAL backend; a fix for it is included in the patch. I revised the code of other backends and they seem to be ok. Anyway would be nice to run regressions to be sure nothing strange is going to happen.

Event Timeline

Thanks, will look at it at some later point.

Any possibility of this patch going into release 2.64?

It was a lot of work but I've rewritten audaspace to use boost::shared_ptr now. Your patch doesn't work, there were too many cases that used the possiblity to create a reference from a plain pointer. Your patch would crash in nearly all cases. Closed.

Joerg Mueller (nexyon) changed the task status from Unknown Status to Resolved.Nov 5 2012, 3:45 PM