adding Lock and Guard for pthread