[omniORB] assert failure during thread creation

Sai-Lai Lo S.Lo@uk.research.att.com
07 Oct 1999 12:02:21 +0100


Andy,

Thanks for the report. How about the alternative:

class tcpSocketWorker : public omni_thread {
public:
  tcpSocketWorker(tcpSocketStrand* s) : omni_thread(s), pd_sync(s,0,0) {
    start();                 
    s->decrRefCount();       // <-- Reach here means we have created a
                             //     thread successfully.
  }
  virtual ~tcpSocketWorker() { }
  virtual void run(void *arg);
  static void _realRun(void* arg);

private:
  Strand::Sync    pd_sync;
};


Just out of interest, what number of threads are you using at the time when
thread create fails?

Sai-Lai



>>>>> Carlson, Andy writes:

> I am testing some code based on the omniORB 2.7.1 source under
> heavy concurrent load. The following problem happens when resources
> are being exhausted, but could be handled more gracefully.

> Here is the code (from tcpSocketRendezvouser::run_undetached)...

> {
> 	// locking & state check stuff omitted

> 	newSt = new tcpSocketStrand(r,new_sock,1);
newSt-> incrRefCount(1);
> }

> // logging stuff omitted

> try {
> 	newthr = new tcpSocketWorker(newSt);
> }
> catch(...) {
> 	newthr = 0;
> }

> if (!newthr) {
> 	// big comment omitted
newSt-> decrRefCount();
newSt-> shutdown();
> }

> The problem is that I sometimes get an assertion failure from
> the newSt->decrRefCount() call. This checks that the refcount
> doesnt go negative after being decremented.

> I think that the problem is this... The tcpSocketWorker is created
> and decrements the strand refcount in its constructor. It then calls
> start() to start the thread. This (I think) is throwing an exception
> which is caught by tcpSocketRendezvouser::run_undetached.

> As newthr hasnt been set, the 'if (!newthr) code is run, which 
> calls decrRefCount again which dies because the refcount was
> already zero.

> Suggested fix: prefix the decrRefCount with if (!newSt->is_idle())


-- 
Sai-Lai Lo                                   S.Lo@uk.research.att.com
AT&T Laboratories Cambridge           WWW:   http://www.uk.research.att.com 
24a Trumpington Street                Tel:   +44 1223 343000
Cambridge CB2 1QA                     Fax:   +44 1223 313542
ENGLAND