Thread-safe timed queue based on locks and conditional vatiables