count variable in not thread safe. it can being changed while another thread is checking condition 'count < max_count'