In this very similar question the problem was multithreading. Are you using multi-threading/-processing?