Most likely, the cause is somewhere else in the code. Something that we can't see (or something more simple that we're overlooking). AGI is definitely not multi-threaded in the sense of executing more than one AGI command at the same time. That would make things extremely difficult because you would not be able to make any assumptions about the order of execution at all.
Besides, typically when there's a concurrency issue, it wouldn't show up every time the program was run. Also, in a typical implementation of threads, you're only guaranteed that your thread won't be preempted at the atomic level (one machine instruction). Even the simple if-statement:
if (f115)
{
reset(f115);
}
is not atomic (your thread might be preempted right after the test "isset(f115)"), so if this were a concurrency issue there really wouldn't be any way to solve it at all, especially since AGI logic lacks typical thread synchronization mechanisms such as critical sections, etc.