working, but counter for threads not working properly - decrement operation seems to be the issue