[ttysrf] Improve thread control and locking.
[ttysrf] Remove redundant code.
[ttysrf] Tidy up test code a little.
[ttysrf] Added debug flags to Makefile.