[haiku-appserver] Re: deadlock

  • From: Adi Oanca <adioanca@xxxxxxxxxxxxxx>
  • To: haiku-appserver@xxxxxxxxxxxxx
  • Date: Thu, 07 Apr 2005 11:28:40 +0300

Hi,

Stefano Ceccherini wrote:
>>      That's what I love about this team!!! When I get short >of ideas, or 
>>when I'm in trouble there is _always_ someone to come with a >nice 
>>solution! :-) Thanks JB.
> 
> Thanks but it is just what beos does, it isn't an original idea of mine :)

        Don't care. You're the one who investigated and solved this problem. :-)

>>      You are right, this solution is _much_ smoother than >what we currently 
>>have in the tree. This means, some things must be changed in 
>>BApplication so that when sending something to the server a 
>>_BAppServerLink_ object should be created instead of locking >the looper.
> 
> 
> Actually, we already use BAppServerLink in BApplication and in the
 > various classes (BCursor, etc.) to handle communication.

        I know. And it's good it's in BPrivate namespace.

> So I think we have just to change a bit the implementation of BAppServerLink:
 > instead of locking be_app, it has to acquire its own (static) lock.
> Does this sound right ? Am I missing something ? Stephan ? Darkwyrm ? Axel ? 
> :)

        Yes, it does. I had a quick look in BApplication and found only one
place where a change is needed: BApplication's destructor.
        I also had a look at BAppServerLink and saw that for each instance it
looks the looper and creates a second reply port. That be_app->Lock() should
disappear and instead of creating a reply port, BApplication's reply port
should be used. Of course let's not forget about that static lock.
        In all, this is what I propose:

BAppServerLink::BAppServerLink(void)
  : BPortLink()
{
        if (be_app)
        {
                mainServerLock->Lock();
                SetSendPort(be_app->fServerFrom);
                SetReplyPort(be_app->fServerTo);
        }
}

BAppServerLink::~BAppServerLink()
{
        if (be_app)
                mainServerLock->Unlock();
}

status_t BAppServerLink::FlushWithReply(int32 *code)
{
        status_t err;

-       err = Attach<port_id>(receiver);
-       if (err < B_OK)
-               return err;
        
        err = Flush();
        if (err < B_OK)
                return err;

        return GetNextReply(code);
}

        Unfortunately some code inside app_server must be changed. That second
reply port was attached to the message.


bye,
Adi.

Other related posts: