[omniORB] What's wrong with me?

edward_lin edward_lin@EGPALM.com.tw
Mon, 21 May 2001 12:47:47 +0800


Hi, 
I happened to find a strange behavior of corba object implementation, it
seemed that the attributes set by first corba client will be overwritten by
the second corba client invocation; the following is the simplifed code
// adder.idl
interface adder {
  short sumAB( );
  attribute short attrA;
  attribute short attrB;
};

// object implementation (simplified)
class adder_i : public virtual POA_adder, 
  public virtual PortableServer::RefCountServantBase
{
public:
  adder_i( ) { }
  ~adder_i( ) { }
  CORBA::Short sumAB() { return a + b; }
  void attrA( CORBA::Short  _a ) { a = _a; }
  CORBA::Short attrA( ) { return a; }
  void attrB( CORBA::Short  _b ) { b = _b; }
  CORBA::Short attrB( ) { return b; }
private:
  short  a, b;
};

// first client
adder_ptr	ap;
ap->attrA(1);
ap->attrB(2);
fgetc(stdin);	// wait for keystroke
cout << ap->sumAB() << endl;

// second client
adder_ptr	ap;
ap->attrA(5);
ap->attrB(6);
cout << ap->sumAB() << endl;

What happend?
I ran first client to set attributes to "1" and "2", the process waited for
the keystroke, at this time, I ran second client to set attributes to "5"
and "6", and console printed "11". That's OK, then I fed a keystroke to the
first client, and it printed unexpected "11", why not "3"? 
What's wrong with me?

Best Regards,
Edward