We have a threaded application that copies files over a network. One thread called PRODUCER connects to database and retrieves file information and fills a buffer. Another thread called CONSUMER reads this buffer and copies the files. The problem is that we have a small function that updates the progress in the databas when the files are copied which is done from the CONSUMER thread. Even those this little function has its own local variable database connection it collides with the connection in the PRODUCER thread. How is this possible? How can we easily solve this? We thought that this would be safe as they do not share connection.