Thanks for the answer.
My question was more about implementation rather than about algorithms.
When working with multithreading it's very easy to make a mistake and very hard to find it. Even tests don't guarantee anything. But them increasing probability to find errors.
I think I'll write some test for your library when I'll integrate it to my projects.