xxxxxxxxxx
shared ISharedAllocator _processAllocator;
shared ISharedAllocator _swapDummy;
shared(ISharedAllocator) processAllocator()
{
foreach(i;0..100)
{
shared a=_processAllocator;
if(cas(&_processAllocator,a,_swapDummy)
&& a!=_swapDummy)
{
a.incRef();
if(!cas(&_processAllocator,
_swapDummy,a))
{
a.decRef();
}
return a;
}
sleep(1);
}
assert(false,"timeout");
}
void processAllocator(shared ISharedAllocator b)
{
b.incRef();
foreach(i;0..100)
{
shared a=_processAllocator;
if(cas(&_processAllocator,a,b))
{
if(a!=_swapDummy)
{
a.decRef();
}
return;
}
sleep(1);
}
assert(false,"timeout");
}