Using threads to solve producer consumer problem