How to setup a FIFO queue to send commands

The title talks about Thread::sleep because they are the most common problem. But locks can pose the same problem.