Ensure that threads terminate properly.

Made sure that CommandListener and FrameListener always terminate
properly by adding a select() call with a timeout of 1s. Also,
made the SimpleExample catch ctrl-c and terminate gracefully.