sched_yield() is designed to handle concurrent threads. It does not understand database access conflicts. Have you set a timeout on every connection to the database ? <https://sqlite.org/c3ref/busy_timeout.html> Set them all to 10 seconds and see what happens.