in reply to
Re^3: Using TheSchwartz - 2 threads pick the same jobs. Any help ?
in thread Using TheSchwartz - 2 threads pick the same jobs. Any help ?
Locking and unlocking tables is a pretty bad way to prevent race conditions compared to just using transactions. Even a pretend "database" like MySQL can support transactions these days. And even in MySQL without transactions, you can still prevent race conditions by making the assignment of a job a single UPDATE statement:
UPDATE joblist SET pid = ? WHERE jobid = ? AND pid IS NULL
(Just as an example and not based on having even glanced at TheSchwartz.) Including "pid IS NULL" in the WHERE clause of the UPDATE is what makes this type of assignment step "atomic".