Say you want to limit your framerate to 60fps, that means that every frame has a render time of 1/60s = 16,67ms (rounded)
To limit your frame rate you just check the time at the start of your game loop, you can then compare it with the time at the end of the game loop: if the difference is less than 16.67ms you should stall for that time.
One way to do this is to use:
sleep(waittime)
However since sleep(x)
yields the thread for a minimum of x
miliseconds you don't know for certain if you will get control back in time.
A better way would be to use:
while(timediff < 16.67ms){ sleep(0); }
This yields the thread and requests control back as soon as possible.
Another solution is to just have a busy wait loop, this gives you the best control but uses the CPU needlessly.
Remember that the OS scheduler can always take away control from your thread so be prepared for some fluctuation.