Vanilla List Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [VANILLA-LIST:2621] Re: SB e-temp bug



On Mon, 23 Aug 1999 you wrote:
>Repost of my posting to rec.games.netrek ...

Did a quick look on the code:

We definitely have a race condition in the dock function.

There is quite some code between:

if (base->p_docked >= NUMPORTS) 

and

  base->p_docked++;

As a test. Can you try to change in orbit.c :

/*
 * If there are bugs in this docking code and/or possibly other places
 * in the code, then conceivably a base my have p_docked < 4 while
 * all ports are non-VACANT.  That is inconsistent, and this code
 * will check for that eventuality on the fly.
 */
#if 1
#define RETURN_IF_VACANT(base, port)
#else
#define RETURN_IF_VACANT(base, port) \
        if (base->p_port[port] != VACANT) { \
          ERROR(1, ("Starbase %d has no ports vacant but p_docked==%d\n", \
                    base->p_id, base->p_docked)); \
          return FALSE; \
        }
#endif

the #if 1 to a #if 0 and check if the bug appears again and if there
are any error messages in the ERRORS file?

As solution you need a (pseudo) atomar test and set operation which you
may achive with

base->p_docked++;
if (base->p_docked > NUMPORTS) 
{
	...
}
else
   base->p_docked--;

This will solve this race condition. On a single CPU machine this code
is 100% save. On a multi processor CPU you only have a theoretical
possibility, that a ship will not dock even if there is a slot free.
But thats not a problem either.

Kurt (007)

--
Kurt Siegl / Franzberg 4, A-4483 Hargelsberg, Austria
Email: 007@netrek.org       Tel (ISDN):   *(7225)7017
URL:   http://www.ooenet.at/user/siegl/kurt/