Threads partially works, some concurrent access error occurs