use semaphore to control queue size

I can't comment on performance, but to me it looks much cleaner implementation.

Tigran.