Your code isn't complete, and it looks like you define $dbh before you spawn your threads.
Threads get a copy of the parent when spawned, so your my $dbh in the thread may not be working.
Try to isolate all the db stuff into the thread code block. Or try to undef $dbh first thing in your thread code block, then redeine it with my. Otherwise, play it safe and fork your code.