Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2005
xdm's Avatar
xdm xdm is offline
ZeroC Staff
 
Name: José Gutíerrez de la Concha Martínez
Organization: ZeroC, Inc.
Project: Ice Developer
 
Join Date: Sep 2003
Location: La Coruña, Spain
Posts: 291
RWRecMutex

Hello i have a problem with RWRecMutex

for example if i have the next slice definition

Code:
           interface Reader
           {
                      nonmutating double getAmount();
           }

           interface Writer
           {
                     idempotent doSameThing();
           }

           class A implements Writer,Reader
           {
                       double total;
                       dobule rest;
           }
and the c++ implementation
Code:
class AI : virtual public A
{
                 virtual doSameThing(const Ice::Current& current);
                 virtual getAmount(const Ice::Current& current)const;
}
in cpp file

Code:
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
Reply With Quote
  #2 (permalink)  
Old 03-22-2005
matthew's Avatar
matthew matthew is offline
ZeroC Staff
 
Name: Matthew Newhook
Organization: ZeroC, Inc.
Project: Internet Communications Engine
 
Join Date: Feb 2003
Location: NL, Canada
Posts: 1,052
Quote:
Originally Posted by xdm
...

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, Matthew
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 08:16 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.