updated lock routine for linux with c++ style casting