Added queue caching, simplified queue code

This seems to make a marginal difference in speed, but reduces code size
a bit.
Added t() to access iteration number

t() is 1 for the first iteration, 2 for the second, etc.  Interopts
that run between periods x and x+1 get x+1 for t().
Threading lock changes

One sync lock wasn't ideal: split it into two: one on stage waiting, one
on done waiting.
g++ warning silencing