I might make this new max-in-flight lock a plain mutex, instead of a RW lock. The critical sections are so short and trivial, and the overhead of the additional complexity of a RW lock are probably not worth it.