I suspect you've got cross-thread data leakage. You cannot, for example, use one thread to query the DB and another to consume the results from that query without making a copy in RAM before passing the data off to the other thread. When was the last time you ran something like [TSAN] or [Helgrind] on that program? [Helgrind]: https://www.valgrind.org/docs/manual/hg-manual.html [TSAN]: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Thread_Sanitizer