"Shift + V" Suspected Race Condition

    Joined
    Aug 23, 2013
    Messages
    379
    Reaction score
    65
    Hi,

    For groups of (AMC, missile, salvager, pulsator, power drain, etc) blocks; "shift + V" links the entire group to the computer, or unlinks the entire group from the computer.

    For larger groups, if you do "shift + V" multiple times too quickly you end up with a mess where some blocks are linked and some aren't. Typically the result is "waves" of linked blocks separated by "waves" of unlinked blocks; where each wave of linked blocks has its own output.

    I suspect this is caused by a race condition, where one thread is linking the blocks to the computer and another thread is unlinking the same blocks at the same time; where the "waves" are caused by one thread getting ahead of or behind the other thread at different times (e.g. a block ends up linked if the "linking thread" gets to it last, and unlinked if the "unlinking thread" gets to it last).

    I see this bug a lot. For an example, I'll have a big group of AMCs (where "big" means several thousand blocks) and change something (while the weapon's computer is not selected to avoid the hideous "purple wobble frame of video card killing doom"), then (when I'm finished changing it) I'll use "shift + V" to unlink the pre-existing blocks and "shift + V" again to relink all the blocks. I've gotten in the habit of waiting for up to 5 minutes (depending on size of the group) in between in the hope of avoiding this bug. Often I don't wait long enough in between (as the game is extremely slow at linking/unlinking) and have to do it all again, but when that happens you need to do "shift + V" twice for each wave of linked blocks to clear the mess; and typically it's faster to just delete the weapon's computer (in an attempt at unlink all at once) and place the weapon's computer back again (and hope the game doesn't think some blocks are still linked to the newly placed computer for no sane reason, which is another bug that also happens).

    Also note that I suspect that the game is acquiring some sort of lock, linking one block, then releasing the lock (and doing that for each block in the group). This would explain the race condition (and the pattern of "waves"), and would also explain why linking/unlinking a large group of blocks is excrutiatingly slow (the overhead of acquiring and releasing locks plus the resulting thread switches when a thread has to wait to acquire a lock). If this is the case both problems may be fixed by doing it in a sane way (specifically; acquire the lock once at the start, then link all blocks, then release the lock). Of course I'm assuming there's one lock per ship/station/asteroid/planet, rather than "excessively fine grained" locking (e.g. one lock per block).