Breakable forever

This patch brings the common logic for Timeout and FdCache to stop their thread and a test case to break forever loops. Relating to #184.

@snoyberg Please review.