Implement a generic cgsem_mswait similar to sem_timedwait