fix deadlock when the reader is closed too early
Merge pull request #49 from alex85k/thread-fix

There is a deadlock if reader is closed too early