added mutex to ensure lifespan of stream object
maximum thread count limit
add test