Add tests against public API, and a t-test for cache speedup
Solve a race between destroy() and the bg_thread going back to sleep