Why are you saving the AI information in so many files (1073741824)?
I'm willing to bet that opening and closing so many file handles is actually the biggest deadlock.
Wouldn't it be better if you would have all this data saved in a single file instead?