Archived
This forum has been archived. Please start a new discussion on GitHub.
RWRecMutex
xdm
La Coruña, Spain
in Help Center
Hello i have a problem with RWRecMutex
for example if i have the next slice definition
and the c++ implementation
Is normal that the servers block here because i invoke a Read opeation inside a Write operation. In this example can be solved easy with chage the code of getAmount to the doSameThing but this solution don't scale well.
how can aboid this ?
thanks in adavantage
for example if i have the next slice definition
interface Reader { nonmutating double getAmount(); } interface Writer { idempotent doSameThing(); } class A implements Writer,Reader { double total; dobule rest; }
and the c++ implementation
class AI : virtual public A { virtual doSameThing(const Ice::Current& current); virtual getAmount(const Ice::Current& current)const; }in cpp file
AI::getAmount(const Ice::Current& const)const { IceUtil::RWRecMutes::RLock sync(this); return total-rest; } AI::doSameThing(const Ice::Current& current) { IceUtil::RWRecMutex::WLock sync(this); if(getAmount()>0) //Server blocked at this point rest++; }
Is normal that the servers block here because i invoke a Read opeation inside a Write operation. In this example can be solved easy with chage the code of getAmount to the doSameThing but this solution don't scale well.
how can aboid this ?
thanks in adavantage
0
Comments
-
xdm wrote:...
Is normal that the servers block here because i invoke a Read opeation inside a Write operation. In this example can be solved easy with chage the code of getAmount to the doSameThing but this solution don't scale well.
how can aboid this ?
thanks in adavantage
Its intended that you cannot acquire a read lock while you hold a write lock. This is illegal, and has undefined behaviour. This is the same semantics as POSIX threads. Its arguable whether hanging is nice though
In this case its pretty easy to rearrange your code to use some internal method that doesn't acquire a lock. Then call the internal method from the external methods.
Regards, Matthew0